On 10/17/2014 01:36 AM, dk wrote:
> took me a little bit to get the self.fields,  since I was trying to
> override directly  as ratiooo.choices.

Yeah, metaclasses are confusing :-)

> and I move the django.setup()  to the top of the file after the imports
> (meantime). not sure what it does, I know that just need to be call
> before any query if not they don't work =(

It sets up the model system (among other things). And yes, it needs to
be called before any database queries occur. But usually you wouldn't
call it in every module that does database queries (though I think you
_can_, it should be idempotent so calling it multiple times doesn't
hurt), usually you would just ensure that it's called once by whatever
script starts up your process. "manage.py" and "wsgi.py" both do this,
so I'm not sure how you're running your Django code that doesn't call
it. If you've got your own startup script of some kind, you should add
django.setup() to it.

> classFormDishes(forms.Form):
>     your_email =forms.EmailField(initial="a...@b.com <mailto:a...@b.com>")
>     ratiooo
> =forms.ChoiceField(choices="",widget=forms.RadioSelect(),initial=1)
>     def__init__(self,*args,**kwargs):
>         self.restaurant_id =kwargs.pop("restaurant_id")
>         super(FormDishes,self).__init__(*args,**kwargs)
>         self.options =self.make_choices()
>         self.fields["ratiooo"].choices=self.options
> 
>     defmake_choices(self):
>         all =Dish.objects.filter(restaurant_id=self.restaurant_id)
>         options_ratio =[]
>         fori inall:
>             options_ratio.append((i.id,i.name))
>         returnoptions_ratio

Looks good!

Carl

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54413A21.2090008%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to