question about foreign key

2009-10-15 Thread jul
uot;Column 'country_id' cannot be null" Or do I have to previously check if the country exists, and creating it if it doesn't? Thanks jul class Country(models.Model): name = models.CharField(max_length=100, unique=True) class Restaurant(models.Model): n

Do I have to pass the httprequest object to render_to_response every time?

2009-10-21 Thread jul
hi, in my base.html template I've got a header which needs httprequest (request.path, request.user.is_authenticated...). In all my views I'm passing the request object to render_to_response. Is there any better way to do that?

Re: Do I have to pass the httprequest object to render_to_response every time?

2009-10-22 Thread jul
But I still have to pass RequestContext(request) to render_to_response if I'm not using generic views, right? On Oct 21, 8:38 pm, Andrew Ingram wrote: > jul wrote: > > hi, > > > in my base.html template I've got a header which needs httprequest > > (request.p

how to save a forms.ModelForm with extra fields?

2009-11-12 Thread jul
user from the context)? thanks jul class Rating(models.Model): user = models.ForeignKey(User) restaurant = models.ForeignKey(Restaurant) rating = models.PositiveSmallIntegerField() class AddRestaurantForm(ModelForm): rating = models.IntegerField() class Meta:

Re: how to save a forms.ModelForm with extra fields?

2009-11-13 Thread jul
anhttp://nomadblue.com/ > > On Fri, Nov 13, 2009 at 5:35 AM, Andy Mckay wrote: > > On 09-11-12 2:33 PM, jul wrote: > >> I've got the Rating model and the AddRestaurantForm shown below. In > >> order to add a rating when submitting a new restaurant, I added

Re: how to save a forms.ModelForm with extra fields?

2009-11-13 Thread jul
in the > model, I think. Also, such extra field in the form, shouldn't it be > form.IntegerField instead of model.IntegerField? > > Hector Garcia - Web developer, musicianhttp://nomadblue.com/ > > On Fri, Nov 13, 2009 at 5:35 AM, Andy Mckay wrote: > > On 09-11-12 2:33

Re: how to save a forms.ModelForm with extra fields?

2009-11-13 Thread jul
What happen to the rating field when doing the following? f = AddRestaurantForm(request.POST) f.save() Does save() only use what it needs to fill the Restaurant instance and doesn't use the rating value? On Nov 13, 5:35 am, Andy Mckay wrote: > On 09-11-12 2:33 PM, jul wrote: > &

Re: how to save a forms.ModelForm with extra fields?

2009-11-13 Thread jul
pointed in his comment. > > Hector Garcia - Web developer, musicianhttp://nomadblue.com/ > > On Fri, Nov 13, 2009 at 11:59 AM, jul wrote: > > What happen to the rating field when doing the following? > > > f = AddRestaurantForm(request.POST) > > f.save() > >

How can I change the values of select options created by a ModelForm?

2009-11-26 Thread jul
hi, I'm generating, using ModelForm, a form from a Restaurant model, which has a Country field. Country has a 'code' and a 'name' fields. When the form is created in my template, the values of the select options are the Country ids. How can I replace them by the Country 'code' values. Is it possib

Issue when saving a model form

2009-11-27 Thread jul
Hi, I've got the ModelForm and Model shown below. I'm overriding the 'city' field to get a CharField instead of a City foreign key. def addRestaurant(request): if request.user.is_authenticated(): if request.method == 'POST': form = AddRestaurantForm(request.POST)

Issue when saving a model form

2009-11-27 Thread jul
Previous post wasn't finished. Wrong key :( Here's the complete one: Hi, I've got the ModelForm and Model shown below. I'm overriding the 'city' field to get a CharField instead of a City foreign key. When saving the Restaurant instance, it returns ""Restaurant.city" must be a "City" instance".

Re: Issue when saving a model form

2009-11-27 Thread jul
recursion errors in > Django, so if that gives you problems, try calling the method all by > itself: > >         # Finish by passing control back tot he normal Django flow: >         forms.ModelForm.save(self, commit) > > Tim > > On Nov 27, 8:57 am, jul wrote: > > >

Re: Issue when saving a model form

2009-11-27 Thread jul
thank you. Excluding city from the ModelForm seems to work as well... class AddRestaurantForm(ModelForm): rating = forms.IntegerField(widget=forms.Select(choices = RATING_CHOICE), required=False) city = forms.CharField(max_length=100) class Meta: model = Restaurant ex

Returning Django objects from Ajax request

2009-12-02 Thread jul
taurant model 3- these instances must be returned to the template. How can I return these objects to the javascript in my template? I'm not using render_to_response with my objects in the context since I think it reloads the whole template? Is that right? thanks jul -- You received this mes

Re: Returning Django objects from Ajax request

2009-12-02 Thread jul
I'm using jQuery post: $.post("/getRestaurant/", location, function(data) { /* stuff */ }); In my view, how do I convert my Restaurant array to json? Thanks for your reply! On Dec 2, 7:52 pm, Javier Guerra wrote: > On Wed, Dec 2, 20

Re: Returning Django objects from Ajax request

2009-12-02 Thread jul
ocs.python.org/library/json.html > > On Dec 2, 2009, at 2:01 PM, jul wrote: > > > I'm using jQuery post: > > > $.post("/getRestaurant/", location, > >          function(data) { > >              /* stuff */ > >          }); > > > In my vie

Question about forms in templates

2009-12-09 Thread jul
ks for any explanation/pointer. jul Name:{{form.name.errors}} {{ form.name }} Country:{{form.country.errors}} {{ form.country }} -- 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...@

Issue with Django form when submitted using jQuery form plugin

2009-12-10 Thread jul
both cases are shown below. thanks jul javascript code: * var is_geocoded = false; var interval; $(function(){ $("#submit").click(function() { var options = { beforeSubmit: getPosition, //

Any way to serialize a pagination object in Django?

2009-12-11 Thread jul
hi, I'm using Django pagination with jQuery. I can serialize the objects list of the pagination object, but I'd like to serialize the whole object to get more data (page number, total number of pages...). How can I serialize the whole pagination object? Thanks ***javascript*** function getResta

customize form in template according to field attribute

2010-01-29 Thread jul
hi, I've got the Category model and SearchForm form shown below. In my template I'd like to get all Category instances having a given type to be able to separate those having different style in my CSS. How can I do this? thanks Jul **Category model*** CATEGORY_TYPE = [ (1, 'r

Re: customize form in template according to field attribute

2010-01-29 Thread jul
I meant: "to be able to separate those having different type in my CSS. " On Jan 29, 12:56 pm, jul wrote: > hi, > > I've got the Category model and SearchForm form shown below. In my > template I'd like to get all Category instances having a given type to &g

Custom form rendering

2010-01-31 Thread jul
rchy of my category instances How can I do that? Do I have to do a custom forms.CheckboxSelectMultiple()? If so, how can I access Category's parents and type? thanks Jul *Category model* CATEGORY_TYPE = [ (1, 'region'), (2, 'type'),

Re: customize form in template according to field attribute

2010-01-31 Thread jul
I reposted this question with more details. On Jan 29, 12:56 pm, jul wrote: > hi, > > I've got the Category model and SearchForm form shown below. In my > template I'd like to get all Category instances having a given type to > be able to separate those having differe

"Illegal mix of collations": how to handle that?

2010-02-27 Thread jul
I'm submitting is not part of my database character set. How can I handle that? Should I first check in the clean function of the field whether all characters are included in my database charset ? Is this not handled by django (I would expect some error before submitting the data to the databas

Re: "Illegal mix of collations": how to handle that?

2010-02-28 Thread jul
Ok, I'll change my database charset. Thanks On Feb 27, 1:06 pm, jul wrote: > hi, > > when submitting some characters in a charfield of a django form I get > the following error (e.g. when submitting 'ś') > > (1267, "Illegal mix of collations (latin1_swedi

How do I get "date.strftime" in the language set by "/i18n/setlang/"

2010-03-02 Thread jul
hi, I have a multilingual site and I'd like to get some date in the current language. With date.strftime, I get the date in english only... The language is set by "/i18n/setlang/". How can I do that? thanks jul -- You received this message because you are subscribed to th

Re: How do I get "date.strftime" in the language set by "/i18n/setlang/"

2010-03-02 Thread jul
Perfect. Thanks. On Mar 2, 6:47 pm, James Bennett wrote: > On Tue, Mar 2, 2010 at 11:19 AM, jul wrote: > > I have a multilingual site and I'd like to get some date in the > > current language. With date.strftime, I get the date in english > > only... > > The l

form.save_m2m() and exclude field

2010-03-15 Thread jul
to save the tag field, while it is excluded. Is the save_m2m() function supposed to save excluded fields? Is there anything wrong in my code? Thanks Jul (...) new_restaurant = form.save(commit=False) new_restaurant.city = city new_restaurant.save() tags = form.cleaned_data['tag'

Re: form.save_m2m() and exclude field

2010-03-15 Thread jul
using the city value from request.POST but from further processing of the data. It still seems to me that save_m2m() tries to save the excluded tag field. Thanks for your help. jul Traceback: File "/var/lib/python-support/python2.5/django/core/handlers/base.py" in get_response 92.

Model.save() behaves differently when used from ModelAdmin.save_model()

2012-07-10 Thread jul
I'm using `ModelAdmin.save_model` to set some data from the `request` object to my instance. When I change an existing `Magasin` instance from the admin, I get an `IntegrityError`, eg: "Duplicate entry '220' for key 'PRIMARY'" meaning that in Model.save, the instance is created, instead of