Re: Reverse Query Name Clash?
This is actually pretty well documented in the django docs. I suggest you look there for a complete explanation, but briefly: with your model definition, the way you would access a minister's church would be: person_object.church and the way you would access the church a person attends would also be person_object.church. Django cannot know the context of what you are trying to get at and therefore does not allow 'reverse' relations with identical names. Changing your code to: minister = models.ForeignKey(Person, related_name='pulpit', null=True, blank=True) removes the conflict allowing you to access a ministers church via person_object.pulpit and the church a person attends via person_object.church obviously, you do not need to use the pulpit, just something other than church, you could also change the related_name on the Person: church = models.ForeignKey(Church, related_name='home_church') and then use person_object.church to get a 'ministers' church and person_object.home_church to get the church a layman attends. Whatever makes more sense to you. One other thing, I am not sure of your exact use-case but you might want to think about making the FK for ministers a M2M just in-case you have a Church with multiple ministers. If it is important to track the type of minister (Senior, Associate, Youth, Music, etc...) you might want to look at using the "through" option of the m2m field definition, consult the docs for more information: http://docs.djangoproject.com/en/1.2/topics/db/models/#extra-fields-on-many-to-many-relationships hth On Nov 1, 9:40 pm, Victor Hooiwrote: > Hi, > > I'm getting a error about reverse query name clashes with my models. > > We have a Django app to manage conferences and conference attendees. > > In our models.py, two of the models we have are: > > 1. Person, representing people attending people attending a > conference. Each person also has a "church" field, which represents > the main church they attend. > > class Person(models.Model): > first_name = models.CharField(max_length=50) > last_name = models.CharField(max_length=50) > gender = models.CharField(max_length=1, > choices=GENDER_CHOICES) > spouse = models.ForeignKey('self', null=True, blank=True) > date_of_birth = models.DateField() > church = models.ForeignKey('Church') > ... > > The "church" FK is in quotation marks, since the Church object is > defined below Person. > > 2. "Church", which defines a church, and includes an optional field > for the main minister at that church. The minister field is a FK to a > Person. > > class Church(models.Model): > name = models.CharField(max_length=50) > address = models.CharField(max_length=50) > suburb = models.CharField(max_length=30) > postcode = models.IntegerField() > state = models.CharField(max_length=3, choices=AUSTRALIAN_STATES) > minister = models.ForeignKey(Person, null=True, blank=True) > > So a person has a church, and a church also has a minister (in most > cases the two will be different, except for the case where the > minister themselves is attending a conference, which should of course > be valid). > > The issue here is that the model doesn't validate: > > Error: One or more models did not validate: > conferences.church: Reverse query name for field 'minister' > clashes with field 'Person.church'. Add a related_name argument to the > definition for 'minister'. > > Now, if I change the name of the "church" field under Person, it will > validate - however, I'm still curious as to why this doesn't work? Any > way to fix it? (I assume I could add a related_name argument, I'm just > trying to figure out what's going on, and gain more understanding for > Django). > > Cheers, > Victor -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Passing view extra info from urls.py
I have looked at the django documentation and searched the group archive for my answer, and believe I know how this is supposed to work, I just cannot figure out why it is not working for me. I want to pass an extra keyword parameter to my view that contains a filter value, but it is not getting passed. Here is the urls.py entry: (r'requirementlibrary/(?P\d+)/requirements/$', 'requirements', {'filter_param':'library'}), and the view: def requirements(request, id=None, filter_param=None): print filter_param the filter_param is always "None" Here is the example from the django docs: (r'^blog/(?P\d{4})/$', 'year_archive', {'foo': 'bar'}), In this example, for a request to /blog/2005/, Django will call the blog.views.year_archive() view, passing it these keyword arguments: year='2005', foo='bar' Anyone know what I a missing? -richard -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ManyToMany lookups
Why not do this: for p in products.objects.all(): for c in p.categories.all(): print p,' - ', c -richard On Oct 20, 7:57 am, Михаил Лукинwrote: > As I know, each category has attribute product_set > > 2009/10/20 ausi1972 > > > > > > > I am trying to work out how to construct a queryset that contains > > multiple records for a ManyToMany field. > > > The models are like this: > > class products(models.Model) > > name = models.CharField() > > categories = models.ManyToManyField(Category) > > > class category(models.Model) > > name = models.Charfield() > > > So a product can be in many categories. > > > I am trying to pull out a list of products with their categories and > > listing the product multiple times if it is in multiple categories. > > > i.e. > > product1 - category1 > > product1 - category2 > > product2 - category1 > > > Any help always appreciated. > > Regards Ausi > > -- > regards, > Mihail --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Model Blues - A Newbie's question
Sure, you can do it, with two (at least) ways, one is to put this into your model so it automatically happens, search the documentation or users group for threadlocals middleware. The other way is to simply put it into your view as all views get the request, request.user will provide you with what you need. On Feb 4, 2:48 pm, nikosk <[EMAIL PROTECTED]> wrote: > I need the default value of a field in a model to be the id of the > user creating the new instance of the object the model is modeling > ( am I making sense at all?) > > i.e. : > class Article(models.Model): > category = models.ForeignKey(Category) > title = models.CharField(max_length=200) > sub_title = models.CharField(max_length=200) > intro_text = models.TextField(blank=True) > main_text = models.TextField() > pub_date = models.DateTimeField(default=datetime.now) > author = models.ForeignKey(User) > > When someone is creating a new Article in the admin app I want the new > Article's author field to be the user's id. > > Is that possible ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: about auth
Cat, I will be posting what I am doing within the next day or to for you. -richard On Sep 27, 8:47 pm, Cat <[EMAIL PROTECTED]> wrote: > Richard > > I am currently developing an interface that will need to use role > based row level permissions and would be greatful for anything that > you are willing to share. > > Catriona > > On Sep 28, 8:53 am, Richard Dahl <[EMAIL PROTECTED]> wrote: > > > If you are interested, I would love to collaborate on some ideas of > > doing this. I have an role-based system working pretty well as of > > now, but it does not, as of yet integrate with the admin interface. > > If you have any interest I would be more than willing to share some > > of what I have come up with. > > -richard > > > On Sep 27, 2007, at 2:38 PM, Lic. José M. Rodriguez Bacallao wrote: > > > > I'll do that > > > > On 9/27/07, Richard Dahl <[EMAIL PROTECTED]> wrote: > > > There is a row-level-permissions branch, but I do not believe it is > > > actively being developed at this time. I wrote my own role-based > > > permission system and integrated it into all of my models that > > > require it. I have not attempted to integrate the permission > > > system into the admin interface though. I have used my own views. > > > If you just want to limit access to one user (+ admin) this can be > > > accomplished relatively easily by storing the user who created the > > > model instance as a FK on the model. The threadlocal middleware > > > can be used to integrate this into your save method of your models, > > > if this is required. You could then create a model.manager to > > > filter based on the request.user, and a model method that can > > > evaluate whether or not the current user is authorized to edit or > > > delete an instance. My advice would be to check the permissions > > > before every action, i.e. check as you create a queryset, when > > > getting an instance for editing, when the edited instance is > > > submitted to be saved, when an instance is to be deleted, etc... > > > If you have any specific questions, I would be more than happy to > > > answer what I can. > > > -richard > > > > On 9/27/07, Lic. José M. Rodriguez Bacallao < [EMAIL PROTECTED]> wrote: > > > hi people, I got a little question, how can I make some users add > > > news (model News), modify only news owned by him or even delete his > > > news, not others users news, but only admins can publish all of them? > > > > -- > > > Lic. José M. Rodriguez Bacallao > > > Cupet > > > - > > > Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos > > > lo mismo. > > > > Recuerda: El arca de Noe fue construida por aficionados, el titanic > > > por profesionales > > > - > > > > -- > > > Lic. José M. Rodriguez Bacallao > > > Cupet > > > - > > > Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos > > > lo mismo. > > > > Recuerda: El arca de Noe fue construida por aficionados, el titanic > > > por profesionales > > > -- Hide > > > quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Newforms validation question
I have an app that uses a roll-my-own role-based access system to restrict access to various model instances. Essentially what happens is that there is a role or roles assigned to users that allow them to either view or edit various asset types based on the owning organization. Many of the assets are related to each other, i.e. devices have applications and buildings have rooms. Everything works fine, including creating my forms, I pass a queryset to my device form application field (modelmultiplechoicefield) that has only the appropriate applications for the device (according to the roles organization). Now I need to figure out the best way to provide validation for this, specifically to ensure that the applications selected coming in via the form post are actually authorized for the role. What I would really love to do is essentially say in a clean method (psuedo code here): If selected_values from applications field are in the applications fields query_set: validate else: raise validationerror (incorrect value) the if statement could also be: for value in selected_values: if not value.is_permissible(role) raise validationerror (incorrect value) If you have ever entered a value that does not exist in the db into a select field, that is the validation error I want to raise I am not sure how best to do this, or where it would be best to put this validation. After searching the list, I haven't found any similar threads, and after reading the newforms docs (again and again) I am not sure if I should subclass the field, or do this in the form, or just forget validation per-se, and put this in the models save() function. The validation is really a corner-case, someone pretty much has to be trying to circumvent the security of the app to make this happen, but I am a security guy by trade, and perhaps more than a little paranoid. I have done this myself using a web proxy and found that while I was able to relate applications that my role was unauthorized to see to devices I was authorized for, my form creation process catches this and fails on the form creation after the save. This could still pose data integrity and denial of service issues though, so I want to catch it during the POST and stop it from propagating any bad juju. I am hoping someone could offer a suggestion. Thanks -richard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using a filter with many to many relationship
Couple of things so I understand better, What is the attribute of term that contains 'ThemePark' and 'London' ? What are you trying to end up with, all records with themePark or only records with themepark and London ? -richard On Sep 16, 11:36 am, merric <[EMAIL PROTECTED]> wrote: > I can't get this to work for me. > > For example, I have two records which both share the term 'ThemePark", > one of these records also has the additional term "London". > However, when I run your suggestion I get an empty query set. > > Cheers > > On Sep 15, 2:27 am, r_f_d <[EMAIL PROTECTED]> wrote: > > > You are missing Q. > > > try > > from django.db.models import Q (I think that is where it resides but > > cannot verify right now, a quick check of the documentation should > > confirm) > > > Offer.objects.filter(Q(terms__exact = 'term1') & Q(terms__exact = > > 'term2') & Q(terms__exact = 'term3)) > > > On Sep 14, 6:46 pm, Merric Mercer <[EMAIL PROTECTED]> wrote: > > > > I have a model "OFFER" that has has many to many relationship with a > > > model "TERMS". > > > > Class OFFER: > > >terms=models.ManyToMany(Terms) > > > > Assuming I have the following value for 3 records in Term > > > term1=2 > > > term2=5 > > > term3=8 > > > > I want to return ONLY those offers which have ALL three of these terms . > > > I've tried: > > > > qs=Offer.objects.all().filter(terms=term1).filter(terms=term2).filter(terms=term3) > > > but this doesn't work - I always end up with an empty query set. > > > > What am I missing? > > > > Cheers --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to link to previous and next objects in object_detail view ?
in that case I cannot be of assistance, I do not use them. -richard On Sep 15, 7:35 pm, akonsu <[EMAIL PROTECTED]> wrote: > sorry i was not clear. i am using django's generic views > infrastructure. django.views.generic.list_detail.object_detail > > http://www.djangoproject.com/documentation/generic_views/#django-view... > > konstantin > > On Sep 15, 8:06 pm, r_f_d <[EMAIL PROTECTED]> wrote: > > > are you using django Generic Views or are you using the word to imply > > non-special views (i.e. you have a number of views just like this.) > > -richard > > > On Sep 15, 6:38 pm, akonsu <[EMAIL PROTECTED]> wrote: > > > > his is my understanding of the problem: > > > > there are two genric views: list view and detail view. the template > > > invoked from the former gets the queryset in the context, and the > > > template invoked from the latter gets the object in the context. note > > > that the latter does not get the queryset, just a single object. in > > > the detail template i do not kow which queryset the list is dealing > > > with, i just know which object i need to display. i am lookng for a > > > way to get three objects in my detail template: the current one that i > > > need to show, the previous one in the order of the queryset (whatever > > > this order might be), and the next one (if they exist). so far django > > > gives my template just the current object when my detail template is > > > called. > > > > konstantin- Hide quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to link to previous and next objects in object_detail view ?
are you using django Generic Views or are you using the word to imply non-special views (i.e. you have a number of views just like this.) -richard On Sep 15, 6:38 pm, akonsu <[EMAIL PROTECTED]> wrote: > his is my understanding of the problem: > > there are two genric views: list view and detail view. the template > invoked from the former gets the queryset in the context, and the > template invoked from the latter gets the object in the context. note > that the latter does not get the queryset, just a single object. in > the detail template i do not kow which queryset the list is dealing > with, i just know which object i need to display. i am lookng for a > way to get three objects in my detail template: the current one that i > need to show, the previous one in the order of the queryset (whatever > this order might be), and the next one (if they exist). so far django > gives my template just the current object when my detail template is > called. > > konstantin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to link to previous and next objects in object_detail view ?
I do not understand how the sequence changes, if the original list is based on a filtered quesryset, couldn't you use the same filter and then what I suggested, i.e. original query foo.objects.filter(bar = 'foobar') next: foo.objects.filter(Q(bar = 'foobar') & Q(id > initial_id)).order_by(id) [:1] or are you not trying to get them ordered by id? -richard On Sep 15, 5:32 pm, akonsu <[EMAIL PROTECTED]> wrote: > thanks, yes this would work if the list in the objects_list view > always contained the same sequence as the database. the problem is > that the list can be arbitrary. i need to get the previous and the > next items from the list and django does not give me anything in the > template context but the object itself. > > konstantin > > On Sep 15, 6:23 pm, r_f_d <[EMAIL PROTECTED]> wrote: > > > I have not tried it with django, so I cannot guarantee this will work, > > however if I understand what you are attempting > > I was showing an model instance in a view and needed to get the next > > one by pk I would probably do: > > model.objects.filter(pk > current_model_instance_id).order_by(id)[:1] > > which should be the next object in the db, by id ascending > > for the previous one I would do the same just with the order_by(-id) > > > Like I said, never done it but I'd give it a try > > > On Sep 15, 1:30 pm, akonsu <[EMAIL PROTECTED]> wrote: > > > > hello, > > > > in my object_detail view i need to emit links to the previous and next > > > objects in the object list which invoked this detail view. has anyone > > > done this? any advice? > > > > thanks > > > konstantin- Hide quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: two questions about data model
for the charfield there is a max_length, but for what you are trying to do, you need to set this in the form widget. Take a look at newforms documentation but to point you in the right direction you need to do something like: where f is your form f.base_fields['FIELDNAME'].widget.attrs = {'size' : 500} which will set the FIELDNAME input with 500 columns for the imagefile entered by it should be entered_by = models.ForeignKey(User, related_name = 'user_entered') or whatever you want to call it. -richard On Sep 15, 12:49 pm, Hai Dong <[EMAIL PROTECTED]> wrote: > Hello: > > I am trying to control the html display size of a CharField using length > keyword. However, I got the following error when doing syncdb > > __init__() got an unexpected keyword argument 'length' > > I am using django svn release. I didn't find length keyword in django > document, but learned it from the django usergroup. > > Another question is in my data model I have > entered_by = models.ForeignKey(User) > > when doing syncdb I got the following where imagefile is a table name. > Accessor for field 'entered_by' clashes with related field > 'User.imagefile_set'. Add a related_name argument to the definition for > 'entered_by'. > > Thanks, > Harry --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to link to previous and next objects in object_detail view ?
I have not tried it with django, so I cannot guarantee this will work, however if I understand what you are attempting I was showing an model instance in a view and needed to get the next one by pk I would probably do: model.objects.filter(pk > current_model_instance_id).order_by(id)[:1] which should be the next object in the db, by id ascending for the previous one I would do the same just with the order_by(-id) Like I said, never done it but I'd give it a try On Sep 15, 1:30 pm, akonsu <[EMAIL PROTECTED]> wrote: > hello, > > in my object_detail view i need to emit links to the previous and next > objects in the object list which invoked this detail view. has anyone > done this? any advice? > > thanks > konstantin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Setting "blank" to one Field?
I am not sure this is possible, null=True is for the database, while blank=True is for form validation. Also there is a datatype None, there is no datatype blank. If you tried to assign blank as apposed to 'blank' to any variable within python it would complain. If there were not a named variable called blank it would tell you that 'blank is not defined', whilst it is easily accomplished to set something to None. Django is written in python and while it does some really cool things easily, it has not implemented a class called blank, afaik. -richard On Sep 14, 1:41 pm, Xan <[EMAIL PROTECTED]> wrote: > Hi, > > Following the database API reference (http://www.djangoproject.com/ > documentation/db-api/): > > If a ForeignKey field has null=True set (i.e., it allows > NULL values), you can assign None to it. Example: > > e = Entry.objects.get(id=2) > e.blog = None > e.save() # "UPDATE blog_entry SET blog_id = NULL ...;" > > I want to know what is equivalent to Blank? That is, how to set > e.blog to blank if blank=True? > > Thanks, > Xan. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using a filter with many to many relationship
You are missing Q. try from django.db.models import Q (I think that is where it resides but cannot verify right now, a quick check of the documentation should confirm) Offer.objects.filter(Q(terms__exact = 'term1') & Q(terms__exact = 'term2') & Q(terms__exact = 'term3)) On Sep 14, 6:46 pm, Merric Mercer <[EMAIL PROTECTED]> wrote: > I have a model "OFFER" that has has many to many relationship with a > model "TERMS". > > Class OFFER: >terms=models.ManyToMany(Terms) > > Assuming I have the following value for 3 records in Term > term1=2 > term2=5 > term3=8 > > I want to return ONLY those offers which have ALL three of these terms . > I've tried: > > qs=Offer.objects.all().filter(terms=term1).filter(terms=term2).filter(terms=term3) > but this doesn't work - I always end up with an empty query set. > > What am I missing? > > Cheers --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Having Django iterate through JSON possible?
The big issue here would be why to do that. If you are doing this synchronously, why put the data into a json object. Just pass a dictionary and do what yo will. If you are doing this ansynchronously (ala AJAX) then the page will not reload and the template will already be compiled and unable to incorporate any new information passed asynchronously. One thing that you can do is to pass a render_to_response call a template and the python dictionary you want modified and let django work its majic on it before returning the '._container' to the page via json. You will still have to use some javascript to display the new information. I use this mechanism extensively in an app I am currently writing, but am partial to the YUI rather than dojo. -richard On Sep 14, 12:35 pm, robo <[EMAIL PROTECTED]> wrote: > Hi, > > I am able to send JSON data from Django to my javascript function, but > I would like to iterate JSON by using the Django template language. Is > this possible at all? > > For example, my view passing JSON back: > def ajax_form_test(request): > data = serializers.serialize("json", Order.objects.all()) > if request.method == 'POST': > return HttpResponse(data, mimetype="application/json") > > And my Javascript function that receives JSON: > >function hello() { > var form_data = { > url: "/ajax_form_test/", > handleAs: "json", > load: function(data){ > dojo.byId("myDiv1").innerHTML = data; > }, > error: function(data){ > alert("Holy Bomb Box, Batman! An error occurred: " + > data); > }, > timeout: 5000, > form: "myForm" > }; > dojo.xhrPost(form_data); >} > > Right now the way my template displays JSON is by using innerHTML as > above. But I would like to convert the data somehow so that Django can > iterate in the {{...}} syntax. > > Thanks, > > robo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: first naive question for a new fresh Django user
Using the code listed (return render_to_response) is going to cause a page refresh (a synchronous operation), if you are trying to use ajax (asynchronously), you should stick the html from the form and the entry into a json or xml object to return to your javascript callback. This is assuming that you are asynchronously submitting the form. I am building an app right now that relies heavily on async connectivity (I am using portions of the YUI in the browser) and I use form_object = render_to_response(template, 'form': form) to format my forms normally, but stick the form_object._container into a response_dict before calling simplejson.dumps(response_dict) on it to format it into json for my callback. -rfd On Sep 11, 4:19 pm, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On Sep 11, 3:11 pm, garonne <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I 've started playing with Django which seems very well for what i > > need but i still can figure out how to implement a very simple ajax > > example: > > > I would like to have a form with a textarea and after pressing the > > button, i wish to see the form and the text print below. For some > > reason i'm not able to keep both on the same page. I put my code > > below. > > If you want both the form and the value of Entry to show at the same > time, you need to pass them both into the context. So this should > work... > > def index(request): > Entry = "No Entry" > if request.method == 'POST': > form = Form(request.POST) > if form['Entry'].data: > Entry = form['Entry'].data > else: > form = Form() > return render_to_response('index.html', {'form': form, > 'Entry':Entry}) > > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
data manipulation in templates or views?
I have been looking at many of the posts in here in recent weeks and wanted to ask any djangurus out there a question to clear up some confusion I have. Should I do data manipulation in my views or in templates. After reading much of the django documentation and working with the framework for the last 18 months or so, I have been doing all of my data manipulation within my views, and using the templates simply for formatting the presentation of the data. Many people have been asking about how to modify the data within the template, i.e. a recent post asking about excel calculations within a template. I do not do any of this in my template, I actually have the need to display statistics regarding some data in an app I am writing, but I do all of the calculations within my view and pass the computed values to my template for display. I hope I am not inviting a quasi-religious war on this issue, but I am wonder if people could provide some insight on when or why I should do this sort of thing within the template (via template tag or not) or if I should continue doing that within the view, which not only currently makes sense to me, but I think is what the official documentation suggests. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: second query question
I believe it would be: Thing.objects.all().exclude(property__property_type__exact = type).distinct() -rfd On Aug 28, 12:24 pm, James Tauber <[EMAIL PROTECTED]> wrote: > There's another query I want to do that I can't seem to wrap my head > around at the moment: > > Say I have a model where Things have Properties each of a particular > PropertyType. So > > class Property(models.Model): > > thing = models.ForeignKey(Thing) > property_type = models.ForeignKey(PropertyType) > value = models.CharField(...) > ... > > I want to find, for a given PropertyType, all the Things that are > lacking any Property of that type. > > Like my previous question, in SQL I could do it with an EXCEPT: > > SELECT id > FROM myapp_thing > EXCEPT > SELECT thing_id > FROM myapp_property > WHERE property_type_id = ... > > How can I best do these sorts of EXCEPT queries with the database API? > > James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Anonymous Users
I am not sure what exactly you want to model in regard to an 'anonymous' user. By definition, these would be users of an application that nothing is required to be known about and can only access information that is provided by views that do not require authenticated users. Generally, if you want to track or store any information about a specific user, you probably would want to create a specific user object/db record for the user and require them to authenticate. If you could be a bit more specific as far as what you would like to know about anonymous users, and how long you would like that information to persist it may be helpful for the list users to respond. -rfd On Aug 27, 10:33 am, "Darrin Thompson" <[EMAIL PROTECTED]> wrote: > Reading the auth docs for Djano 0.96, it appears to me that there is > no model backing the idea of an anonymous user. > > Before I read the docs I was expecting that I could let my model refer > to users and some of them would be anonymous, some of them real. > > Now I'm sure that the Django developers have good reason to have > designed things as they did, but how have others dealt with modeling > the idea of a possibly anonymous user? > > -- > Darrin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Flexible Models?
I will not say that it is pretty, but, I looked into doing this a while ago for an app I am developing. I wanted to create a system that could inventory and track many different types of assets, and allow for users to essentially create additional asset types on the fly. Essentially, I decided upon using meta-tables to provide the flexibility, it passed the smell-test with a couple of database architect friends of mine (not my specialty), but was essentially too complex to provide enough return for my particular situation. What I came up with is something like this (code is abbreviated, and this is off the top of my head): class attributetype(model): data_type_choices=(bool, text, char, int) name = charfield() number_allowed = intfield() data_type = charfield(choices=data_type_choices) class attribute(model): type = foreignkey(attributetype) booldata = booleanfield() textdata = charfield() intdata = integerfield() def __str__(self): if type.data_type == text: return('%s' % textdata) if type.data_type == char: etc class AssetType(Model): name = charfield() attribute_types = manytomany(attributetype) class Asset(Model): name = models.charfield() type = models.foreignkey(assettype) attributes = manytomany(attributes) Building a form for adding or updating an Asset was obviously not trivial. You would have to write a function that would look at the asset type, and create formfields for the asset based on what attributetypes and the number allowed by the attribute defined. This did mean though, that if I had two assets that shared an attribute but had conflicting numbers allowed, I needed to create two separate attribute types. Using (something like) this I could create any kind of asset I wanted to and create the necessary attributes required to store pertinent information. Like I said, the complexity outweighed what I believed to be the return in my particular case. Hope this helps. -rfd On Aug 24, 11:29 am, "Nathaniel Martin" <[EMAIL PROTECTED]> wrote: > Hmmm, that's an interesting method. I was hoping for some way to add > attributes though. Does anyone else have any ideas? > -Nate > > On 8/23/07, Thomas Guettler <[EMAIL PROTECTED]> wrote: > > > > > Am Freitag, 24. August 2007 00:50 schrieb Nathaniel Martin: > > > I'm hoping that some of the django experts on this list can help me with > > a > > > problem I'm working on designing the architecture of a site I'm working > > on. > > > I want to have many objects that each belong to a category. Each > > category > > > has a bunch of attributes. Each object would set values for each of > > those > > > attributes. > > > ... > > [cut] > > > B) Have an 'Objects' table, a 'Categories' table, and multiple > > 'Attributes' > > > tables, one for each datatype I think will be used. The 'Objects' table > > has > > > a column tying it to a certain category. The 'Categories' table has a > > > column for each attribute table, and lists which attributes are used for > > > which table. Each 'Attribute' table stores all the attributes of that > > > datatype, with a column pointing to which category and object it's for. > > > > Downsides: Really complicated. I can see this getting very messy very > > > quickly. Lots of tables. > > > I have started an application that uses this approach. It is far from > > being > > finished. I do something like inheritance at database level: > > > One Category can have an other Category as parent. A subcategory has > > all the attributes of its parent and grandparents. > > > The user can: > > - change the hierarchie of categories > > - add categories > > - add existing attributes to categories > > > Up to now he can't: > > - add new attributes. ( > > This would need a python file and something like syncdb. > > That should be done by a developer) > > > Thomas --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: insert or update
As far as insert or update, just overide the save method within the class. It is something that must be done for each class, but what I have done (for essentially the same purpose) is override save() on each model I need to log the action for like so: def save(): # if id exists, this record has already been created if foo.id: # create the log entry for an update else: # create the log entry for an insert super(foo, self).save() Do the same for delete() To make it easier I have abstracted my save and delete methods, they are defined as methods within my apps models.py and the individual model classes call them, passing (self) and getting back a 'model_instance' object for user with the super.save() -rfd On Aug 21, 1:20 pm, "Lic. José M. Rodriguez Bacallao" <[EMAIL PROTECTED]> wrote: > how can I know programatically if an operation in a model is an insert, > update or delete? > I just want to extend the admin log to log any action in my application > models. Right now, > admin app only log actions executed by itself. > > -- > Lic. José M. Rodriguez Bacallao > Cupet > - > Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo > mismo. > > Recuerda: El arca de Noe fue construida por aficionados, el titanic por > profesionales > - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using queryset values() spanning relationships
You should be able to do this: p = Publisher.objects.get(pk=1) authors = Author.objects.filter(book__publisher__exact = p).distinct() list = ([(a.id, a.name) for a in authors]) I don't have a python shell handy so I do not know for sure that the syntax is correct, but I do things like this all the time with Django. -rfd On Aug 14, 2:42 pm, NickJ <[EMAIL PROTECTED]> wrote: > Sorry, think I've answered my own question: Further searching found a > similar request in developers a couple of months back: > > http://groups.google.com/group/django-developers/browse_thread/thread... > > Which didn't get any love. So I guess I'll need to drop in to SQL for > now. > > On Aug 14, 4:34 pm, NickJ <[EMAIL PROTECTED]> wrote: > > > Take 3 models: > > > class Publisher(models.Model): > > name = models.CharField() > > > class Author(models.Model): > > name = models.CharField() > > > class Book(models.Model): > > publisher = models.ForeignKey(Publisher) > > authors = models.ManyToManyField(Author) > > > i.e. a book must have one or more authors, and must have one > > publisher. > > > What i want is to get a distinct list of all authors for a specific > > publisher. Is this possible without dropping back to raw SQL? > > > I want to do something like: > > > p = Publisher.objects.get(pk=1) > > list = p.book_set.values('publisher__id', 'publisher__name').distinct() --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Need some advice in new project
I am not sure why you would want "all companies bank accounts in different tables." Is it for security? to ensure that only appropriate people are able to view the records of any given company? There is the row-level-permissions branch, but I do not believe it has been maintained in a while so I rolled my own by implementing a very simple row-level access based on the 'organization' that a user belongs to. You may want to consider something like this. -r On Jul 28, 1:47 pm, anna <[EMAIL PROTECTED]> wrote: > Hello my friends. > > I need your help in designing our new based application. > The goal is to build a kind of backoffice system, which helps to > organize all data of a specific company. > No problem with it. Build your models, data structures, input and > output 'screens'. > > But... > this application goes to a 'proxy' company, who's job is organize > other companies data. (Assume its an accounting firm, for example) > All models etc. are the same in each, but we expressly don't want to > store same data in same table (i mean all companies bank accounts are > in different tables) > We have to create new 'database' dynamically from a web based > interface seamlessly. > Did you solve similar problem already? > Prefixing tables, different databases or what? > > Thank you for any advice. > > Anna --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to make a field that can be inserted but not updated?
I realized after I posted this that I did not explain it well, so here goes try number two. The editable=false affects the admin interface and I believe the newforms module and perhaps the old manipulator framework. You can simply create your own form, particularly with a model this simple, and do your own validation (see the docs for how to do this) for the form after checking to see that the user is a super user. Also after re-reading your post my question is whether or not what you are really trying to accomplish would require the user field to be editable=false as well. This would ensure that the email address could not be changed, and that the user associated with the email address could not be changed without using a custom view that was limited to the super user. hth, -r On Aug 10, 9:48 pm, r_f_d <[EMAIL PROTECTED]> wrote: > If I am not mistaken, editable=False is only applicable to the admin- > forms. Simply create a view that checks to see if the user is a > superuser and then give them a form to add an email address. > > peace, > -r > > On Aug 10, 7:59 pm, Russell Blau <[EMAIL PROTECTED]> wrote: > > > I am working on an application that includes the following in > > models.py: > > > class UserEmail(models.Model): > > email = models.EmailField("email address", unique=True, > > editable=False) > > user = models.ForeignKey(UserRegistration) > > > # an email address can only be associated with one user, and can > > never > > # be deleted > > # once assigned to a user, it can be shifted to another user only > > by > > # manual intervention by an administrator > > > def delete(self): > > "Deletion of email addresses is not permitted" > > warnings.warn("Attempt to delete registered email %s > > rejected." > > % self.email) > > > def __str__(self): > > return self.email > > > class Admin: > > pass > > > Basically, I want to keep track of every email address that has ever > > been registered with my app, to prevent duplication. By overriding > > delete(), I prevent any address from being removed from the database, > > but I also have to prevent editing the address once it has been > > registered. The problem is that "editable=False" works too well -- it > > prevents an admin from editing an existing address, but also prevents > > them from adding new ones. Is there a way to set up my model so that > > the administrator can enter new email addresses for a user, but cannot > > change the existing ones? > > > Russ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Saving a copy of a model
I also forgot to mention two things, the model documentation states that each model subclasses django.db.models.Model, and I believe it will not work to subclass a model. I believe I tried this when I first started with Django last year and it would not work. Secondly, based on your coment that you have been playing with and learning about manipulators for a few hours now, if you are new to Django, you may want to avoid using Manipulators as the newforms will be replacing them, if not before, in Version 1. -richard On Aug 10, 10:18 pm, r_f_d <[EMAIL PROTECTED]> wrote: > I am not sure I understand, I think you want to archive a model > instance? or put another way, when the model is no longer active or > useful to the user, you would essentially like to treat that database > record differently than other records. In that case, you could simply > change the archived field to a boolean, set true on it when you > archive it, and the modified field would automatically record the > date. Then all you have to do is filter out all of the archived or > non archived models via Assessment.objects.filter(archived__exact = > True) or = False. This would make your views much easier to customize > as would only be dealing with one model. > hth, > -richard > > On Aug 10, 7:40 pm, Carlos Hanson <[EMAIL PROTECTED]> wrote: > > > Greetings, > > > I have a model which I would like to archive. My thought was to > > extend that model with one additional DateTimeField called archived. > > But I am having difficulty saving an instance of the archived object > > based on an existing object. > > > class Assessment(models.Model): > > student = models.ForeignKey(Student) > > created = models.DateTimeField(auto_now_add=True, editable=False) > > modified = models.DateTimeField(auto_now=True, editable=False) > > background = models.TextField(blank=True) > > ... > > > class ArchivedAssessment(Assessment): > > archived = models.DateTimeField(auto_now_add=True, editable=False) > > > I am working within the admin interface and creating a view to take > > the saved Assessment and save it as an ArchivedAssessment. It seems > > like it should be relatively easy to do, but I am not seeing how. > > I've been learning about and playing with Manipulators for a couple > > hours now. > > > Any suggestions? > > > Carlos Hanson --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Saving a copy of a model
I am not sure I understand, I think you want to archive a model instance? or put another way, when the model is no longer active or useful to the user, you would essentially like to treat that database record differently than other records. In that case, you could simply change the archived field to a boolean, set true on it when you archive it, and the modified field would automatically record the date. Then all you have to do is filter out all of the archived or non archived models via Assessment.objects.filter(archived__exact = True) or = False. This would make your views much easier to customize as would only be dealing with one model. hth, -richard On Aug 10, 7:40 pm, Carlos Hanson <[EMAIL PROTECTED]> wrote: > Greetings, > > I have a model which I would like to archive. My thought was to > extend that model with one additional DateTimeField called archived. > But I am having difficulty saving an instance of the archived object > based on an existing object. > > class Assessment(models.Model): > student = models.ForeignKey(Student) > created = models.DateTimeField(auto_now_add=True, editable=False) > modified = models.DateTimeField(auto_now=True, editable=False) > background = models.TextField(blank=True) > ... > > class ArchivedAssessment(Assessment): > archived = models.DateTimeField(auto_now_add=True, editable=False) > > I am working within the admin interface and creating a view to take > the saved Assessment and save it as an ArchivedAssessment. It seems > like it should be relatively easy to do, but I am not seeing how. > I've been learning about and playing with Manipulators for a couple > hours now. > > Any suggestions? > > Carlos Hanson --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to make a field that can be inserted but not updated?
If I am not mistaken, editable=False is only applicable to the admin- forms. Simply create a view that checks to see if the user is a superuser and then give them a form to add an email address. peace, -r On Aug 10, 7:59 pm, Russell Blau <[EMAIL PROTECTED]> wrote: > I am working on an application that includes the following in > models.py: > > class UserEmail(models.Model): > email = models.EmailField("email address", unique=True, > editable=False) > user = models.ForeignKey(UserRegistration) > > # an email address can only be associated with one user, and can > never > # be deleted > # once assigned to a user, it can be shifted to another user only > by > # manual intervention by an administrator > > def delete(self): > "Deletion of email addresses is not permitted" > warnings.warn("Attempt to delete registered email %s > rejected." > % self.email) > > def __str__(self): > return self.email > > class Admin: > pass > > Basically, I want to keep track of every email address that has ever > been registered with my app, to prevent duplication. By overriding > delete(), I prevent any address from being removed from the database, > but I also have to prevent editing the address once it has been > registered. The problem is that "editable=False" works too well -- it > prevents an admin from editing an existing address, but also prevents > them from adding new ones. Is there a way to set up my model so that > the administrator can enter new email addresses for a user, but cannot > change the existing ones? > > Russ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
return html snippet via XHR with simplejson
I was wondering what people are doing to format html snippets returned via XHR. I am currently using code like: response_dict = {} t = ModelObject.objects.all() html_table = render_to_response('table_template.html', {'table': t}) response_dict.update({'table': html_table}) return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript') Where my template contains code to loop through the queryset and layout the table appropriately. I also do this with form_for_model(instance) to layout the form fields. This seems pretty appropriate to me, but as I am relatively new to python and django, I was wondering if others are doing something similar or if there are other suggestions for returning the html formatted. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---