Re: ModelAdmin Media JS file order issue in Django 2.0

2017-12-10 Thread Marc R
because they are specific to only a few models, particularly the loading 
scripts, and options, etc.  this worked great in Django 1.11

On Sunday, 10 December 2017 09:36:56 UTC-5, Etienne Robillard wrote:
>
> Why don't you simply put the javascripts into your base template without 
> using Python ? 
>
> Etienne
>
> Le 2017-12-10 à 09:30, Marc R a écrit :
>
> I have this in my model: 
>
> class Media:
> js = (
>* '/static/plugins/codemirror/lib/codemirror.js',*
> '/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js',
> '/static/plugins/codemirror/addon/fold/foldcode.js',
> '/static/plugins/codemirror/addon/fold/foldgutter.js',
> '/static/plugins/codemirror/addon/fold/brace-fold.js',
> '/static/plugins/codemirror/addon/fold/indent-fold.js',
> '/static/plugins/codemirror/addon/fold/comment-fold.js',
> '/static/plugins/codemirror/addon/fold/xml-fold.js',
> '/static/plugins/codemirror/addon/comment/comment.js',
> '/static/plugins/codemirror/addon/edit/matchbrackets.js',
> '/static/plugins/codemirror/addon/edit/matchtags.js',
> '/static/plugins/codemirror/mode/javascript/javascript.js',
> '/static/plugins/codemirror/mode/xml/xml.js',
> '/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js',
> '/static/plugins/codemirror/addon/display/fullscreen.js',
> '/static/js/admin/syslog/syslog_change_form.min.js'
> )
>
> which used to work as it was included in the model admin page in the order 
> it appears. However, now in Django 2.0, it appears in this order:
>  src="/static/plugins/codemirror/addon/fold/foldcode.js">
>  src="/static/plugins/codemirror/addon/fold/foldgutter.js">
>  src="/static/plugins/codemirror/addon/fold/brace-fold.js">
>  src="/static/plugins/codemirror/addon/fold/indent-fold.js">
>  src="/static/plugins/codemirror/addon/fold/comment-fold.js">
>  src="/static/plugins/codemirror/addon/fold/xml-fold.js">
>  src="/static/plugins/codemirror/addon/comment/comment.js">
>  src="/static/plugins/codemirror/addon/edit/matchbrackets.js">
>  src="/static/plugins/codemirror/addon/edit/matchtags.js">
>  src="/static/plugins/codemirror/mode/javascript/javascript.js">
>  src="/static/plugins/codemirror/mode/xml/xml.js">
> * src="/static/plugins/codemirror/lib/codemirror.js">*
>  src="/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js">
>  src="/static/plugins/codemirror/addon/display/fullscreen.js">
>  src="/static/js/admin/syslog/syslog_change_form.min.js">
>
> The issue is that the First file MUST be first as the remainder rely upon 
> it!  I'd rather not override a template file as if i change the admin 
> backend with a package i'd like this to "just work" as it did in Django 1.11
> Is this a bug in the new way that Django includes these files (docs say 
> they made a change in how this is done, clearly it broke something that 
> worked!).
>
> Thanks
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5ad93160-05c2-4251-84ad-6f8a1574b675%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/5ad93160-05c2-4251-84ad-6f8a1574b675%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> Etienne robillardtka...@yandex.com 
> https://www.isotopesoftware.ca/
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8493b435-1574-4187-88f6-7f45f5dbaba6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ModelAdmin Media JS file order issue in Django 2.0

2017-12-10 Thread Marc R
I have this in my model:

class Media:
js = (
   * '/static/plugins/codemirror/lib/codemirror.js',*
'/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js',
'/static/plugins/codemirror/addon/fold/foldcode.js',
'/static/plugins/codemirror/addon/fold/foldgutter.js',
'/static/plugins/codemirror/addon/fold/brace-fold.js',
'/static/plugins/codemirror/addon/fold/indent-fold.js',
'/static/plugins/codemirror/addon/fold/comment-fold.js',
'/static/plugins/codemirror/addon/fold/xml-fold.js',
'/static/plugins/codemirror/addon/comment/comment.js',
'/static/plugins/codemirror/addon/edit/matchbrackets.js',
'/static/plugins/codemirror/addon/edit/matchtags.js',
'/static/plugins/codemirror/mode/javascript/javascript.js',
'/static/plugins/codemirror/mode/xml/xml.js',
'/static/plugins/codemirror/mode/htmlmixed/htmlmixed.js',
'/static/plugins/codemirror/addon/display/fullscreen.js',
'/static/js/admin/syslog/syslog_change_form.min.js'
)

which used to work as it was included in the model admin page in the order 
it appears. However, now in Django 2.0, it appears in this order:











**




The issue is that the First file MUST be first as the remainder rely upon 
it!  I'd rather not override a template file as if i change the admin 
backend with a package i'd like this to "just work" as it did in Django 1.11
Is this a bug in the new way that Django includes these files (docs say 
they made a change in how this is done, clearly it broke something that 
worked!).

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ad93160-05c2-4251-84ad-6f8a1574b675%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Passing filter parameters to admin's add view

2013-05-26 Thread Marc R
Sorry, didn't read to the bottom of your post :)

Why would there be a better way than overriding the default template?  that 
is the most efficient way and the power of frameworks.

On Saturday, May 25, 2013 11:53:00 AM UTC-4, Branko Majic wrote:
>
> Hello all, 
>
> I've posted a similar question a couple of months ago, but received no 
> answer. I'm repeating the question now, but hopefully making it a bit 
> clearer on what I desire to achieve. 
>
> Is there any way to have the admin app pass the currently set filter 
> (GET prameters) to the "add view"? 
>
> For example, let's say that the following page is open: 
>
> http://localhost:8000/admin/conntrackt/entity/?project__id__exact=1 
>
> By default the page will contain the "Add item" link as: 
>
> http://localhost:8000/admin/conntrackt/entity/add/ 
>
> What I'm interested in doing would be to have this link instead as: 
>
> http://localhost:8000/admin/conntrackt/entity/add/?project__id__exact=1 
>
> The idea is to take advantage of the current filter in the list view in 
> admin in order to limit the foreign key fields when adding a new 
> entity. 
>
> I've already implemented this by overriding the admin's 
> change_list.html template, but I'd be a bit surprised that there isn't 
> a better way to perform this. 
>
> Best regards 
>
> -- 
> Branko Majic 
> Jabber: bra...@majic.rs  
> Please use only Free formats when sending attachments to me. 
>
> Бранко Мајић 
> Џабер: bra...@majic.rs  
> Молим вас да додатке шаљете искључиво у слободним форматима. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Passing filter parameters to admin's add view

2013-05-26 Thread Marc R
override the template and change it accordingly (you can grab djangos as a 
starting point).  Google for django admin template override.


On Saturday, May 25, 2013 11:53:00 AM UTC-4, Branko Majic wrote:
>
> Hello all, 
>
> I've posted a similar question a couple of months ago, but received no 
> answer. I'm repeating the question now, but hopefully making it a bit 
> clearer on what I desire to achieve. 
>
> Is there any way to have the admin app pass the currently set filter 
> (GET prameters) to the "add view"? 
>
> For example, let's say that the following page is open: 
>
> http://localhost:8000/admin/conntrackt/entity/?project__id__exact=1 
>
> By default the page will contain the "Add item" link as: 
>
> http://localhost:8000/admin/conntrackt/entity/add/ 
>
> What I'm interested in doing would be to have this link instead as: 
>
> http://localhost:8000/admin/conntrackt/entity/add/?project__id__exact=1 
>
> The idea is to take advantage of the current filter in the list view in 
> admin in order to limit the foreign key fields when adding a new 
> entity. 
>
> I've already implemented this by overriding the admin's 
> change_list.html template, but I'd be a bit surprised that there isn't 
> a better way to perform this. 
>
> Best regards 
>
> -- 
> Branko Majic 
> Jabber: bra...@majic.rs  
> Please use only Free formats when sending attachments to me. 
>
> Бранко Мајић 
> Џабер: bra...@majic.rs  
> Молим вас да додатке шаљете искључиво у слободним форматима. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Is there a way to tell an instance was saved without checking instalce.pk or doing a db lookup?

2013-05-26 Thread Marc R
What are you trying to accomplish?

I believe the doc's talk about this some; but in short,  you can only check 
the pk if its a new object; otherwise the pk would be set (if you retrieved 
the object from the database, or saved before).

I would assume (as i've not run into the issue yet) that on a save() to the 
object, if it fails you'll get an exceptions thrown.

On Saturday, May 25, 2013 4:01:29 PM UTC-4, Sergiy wrote:
>
> To check if the instance was saved one might do something like this:
>
> def is_instance_saved(instance):
> if instance.pk is None:
> return False
> # in case pk was set manually
> try:
> instance.__class__.objects.get(pk=instance.pk)
> except ObjectDoesNotExist:
> return False
> return True
>
> I wonder if the instance already knows whether it was saved or not 
> (through some sort of private attribute).
>
> Thanks
> Sergiy
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




another ifchanged question, triggers on first call, not what I want

2013-05-26 Thread Marc R
I'm trying to insert breaks when a row value in a specific column of data 
changes; however, it is triggering on the very first call to "ifchanged".

For example:

{% for row in report %}
{% ifchanged row.column2 %}  {% endifchanged %}
...print other data...
{% endfor %}
 
The very first line is a "" with the above sample.

Although technically the ifchanged, did change (from Null/None, to some 
value), I don't believe the assignment should count as an actual change.

Is there a way around this behaviour?

Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Marc R
Anyone? I would really like to know who I can modify the query as its being 
built so that for a specific field I can set the "field" to 
AES_DECRTYP(fieldname,key) on a select and AES_ENCRYPT(fieldname,key) on 
insert/update

On Sunday, 28 April 2013 20:21:48 UTC-4, Marc R wrote:
>
> I have a model where I have used AES_ENCRYPT(value, key) to save data in a 
> MySQL database.  It is set as a varbinary field.
>
> So the issue is; when trying to edit the model in Django, it does not 
> render a widget for the field.
>
> I've tried the aesfield from github but that does some funky thing with 
> HEX and tagging the type of encryption used.  Not what I want, as the 
> database already has 8300 records and other applications that access it 
> using queries like
> select field1, field2, AES_DECRYPT(field3, 'key') from ...
>
> So I can't change how the data is stored or I'll break the other 
> applications.
>
> How can I setup customer "SELECT' and "SAVE" (insert, update), queries for 
> a model in django?
> Or am I stuck creating my own form and processing and related CRUD 
> operations for this Model?
>
> Thanks,
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Admin module - modify SQL Query used for Edit and Save Models

2013-04-28 Thread Marc R
I have a model where I have used AES_ENCRYPT(value, key) to save data in a 
MySQL database.  It is set as a varbinary field.

So the issue is; when trying to edit the model in Django, it does not 
render a widget for the field.

I've tried the aesfield from github but that does some funky thing with HEX 
and tagging the type of encryption used.  Not what I want, as the database 
already has 8300 records and other applications that access it using 
queries like
select field1, field2, AES_DECRYPT(field3, 'key') from ...

So I can't change how the data is stored or I'll break the other 
applications.

How can I setup customer "SELECT' and "SAVE" (insert, update), queries for 
a model in django?
Or am I stuck creating my own form and processing and related CRUD 
operations for this Model?

Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ManyToMany relationship and raw sql queries

2013-04-27 Thread Marc R
did you use Bookmark.objetcs.all().select_related() ?

As this will create a join query... at least for your model you show in the 
message I have found that for very complex joins, you need to use raw 
query and not a Model.

On Thursday, April 25, 2013 10:44:28 AM UTC-4, Matthieu Bouron wrote:
>
> On Thursday, April 11, 2013 5:39:57 PM UTC+2, Tom Evans wrote:
>>
>> On Thu, Apr 11, 2013 at 3:42 PM, Matthieu Bouron 
>>  wrote: 
>> > Hello, 
>> > 
>> > Is there a way to handle many-to-many relationship with raw sql queries 
>> ? 
>> > I have the following model: 
>> > 
>> > from django.db import models 
>> > 
>> > class Tag(models.Model): 
>> > name = models.CharField(max_length=512, unique=True) 
>> > 
>> > class Bookmark(models.Model): 
>> > link = models.CharField(max_length=512) 
>> > title = models.CharField(max_length=512) 
>> > tags = models.ManyToManyField(Tag) 
>> > added_at = models.DateField() 
>> > 
>> > Using Bookmark.objetcs.all() will result in a subquery for each row of 
>> the 
>> > bookmark table which is not acceptable for performance reasons. 
>> > First question is there a way to fetch all the content with a single 
>> query ? 
>> > Second question is it possible to use raw sql queries. I tried the 
>> > following: 
>> > 
>> > bookmarks = Bookmark.objects.raw( 
>> > 'SELECT * FROM bookmarkmanager_bookmark b ' 
>> > 'LEFT JOIN bookmarkmanager_bookmark_tags bt ON (
>> b.id = 
>> > bt.bookmark_id) ' 
>> > 'LEFT JOIN bookmarkmanager_tag t ON (bt.tag_id = 
>> t.id)' 
>> > ) 
>> > 
>> > But when i tried to access the tags attribute on a bookmark i get the 
>> > following exception: 
>> > 
>> > ValueError: "" needs to have a value for 
>> field 
>> > "bookmark" before this many-to-many relationship can be used. 
>> > 
>> > Thanks in advance, 
>> > Matthieu 
>> > 
>>
>> Are you tied to raw SQL queries? Django itself supports traversing M2M 
>> relationships in a sane manner if you tell it to do so: 
>>
>>
>> https://docs.djangoproject.com/en/1.5/ref/models/querysets/#prefetch-related 
>>
>
> Thanks.
> Another problem remains ... performances are horrible even if i use 
> values().
> I have 1000 rows in base, executing from a script (db sqlite):
>   - 800ms to fetch all the objects (traversing m2m with prefetch_related).
>   - 200ms to fetch all the row from bookmark table without traversing the 
> m2m relationship).
>
> Are my results expected ?
> Are there any plan on improving django orm performance ?
>
> Matthieu
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django Admin - BooleanField issue

2013-04-27 Thread Marc R
That seems to have worked... I used 1 and 0 as the database is set for a 
tinyint to store the value (so needs to be 1 or 0).  That said, 
django/python seems to figure that out when saving the value.

Thanks; wouldn't have thought to try that.

On Saturday, 27 April 2013 14:46:14 UTC-4, Andrew Boltachev wrote:
>
> Hi. May be you need
>
> active = models.BooleanField(choices=((True,'yes'),(False,'no')))
>
> ?
>
> - With regards, Andrei
>
>
> 2013/4/27 Marc R >
>
>> I've setup a boolean field and get it to display correctly using this in 
>> my model:
>> active = models.BooleanField(choices=((1,'yes'),(0,'no')))
>>
>> However, when I edit a record in the Django Admin, the select field 
>> always shows "yes" regardless of the database value.
>>
>> Saving "yes" or "no" stores the correct 1 or 0; is there a bug in the 
>> edit form?  Or did I miss a setting?
>>
>> Thanks,
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django Admin - BooleanField issue

2013-04-27 Thread Marc R
I've setup a boolean field and get it to display correctly using this in my 
model:
active = models.BooleanField(choices=((1,'yes'),(0,'no')))

However, when I edit a record in the Django Admin, the select field always 
shows "yes" regardless of the database value.

Saving "yes" or "no" stores the correct 1 or 0; is there a bug in the edit 
form?  Or did I miss a setting?

Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.