Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-02 Thread Tom Evans
On Wed, Nov 2, 2011 at 12:15 PM, Jaroslav Dobrek wrote: > I now use ManyToManyFields and hide certain data from administrators > by simply not importing them into admin.py. What I don't like about > this solution is that this data still is in the database and not in my

Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-02 Thread Jaroslav Dobrek
On 1 Nov., 18:54, Mark Furbee <markfur...@gmail.com> wrote: > As alluded to previously, the most "straightforward way to use a set of > choices of which several can be chosen" IS to use a ManyToManyField. The > syntax is slightly different, but ManyToManyFiel

Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-02 Thread Mark Furbee
As alluded to previously, the most "straightforward way to use a set of choices of which several can be chosen" IS to use a ManyToManyField. The syntax is slightly different, but ManyToManyFields are really easy to use with Django. Do not reinvent the wheel in this case. Thanks, M

Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-01 Thread J. Cliff Dyer
Candidate(models.Model): programming_languages = models.CharField(max_length=50, choices=( (u'Python)', u'Python'), (u'C++', u'C++'), (u'Java', u'Java'), # ... ), blank=True) with the only exception that, in the admin interface

Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-01 Thread Tom Evans
e above code was to express that I wanted to use this code > > class Candidate(models.Model): > >    programming_languages = models.CharField(max_length=50, choices=( > >            (u'Python)', u'Python'), >            (u'C++', u'C++'), >            (u'Java', u'Ja

Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-01 Thread Jaroslav Dobrek
guages = models.CharField(max_length=50, choices=( (u'Python)', u'Python'), (u'C++', u'C++'), (u'Java', u'Java'), # ... ), blank=True) with the only exception that, in the admin interface, several choices are possible when one creates

Re: Set of choices of which several can be chosen without using a ManyToManyField

2011-11-01 Thread Tom Evans
On Tue, Nov 1, 2011 at 11:07 AM, Jaroslav Dobrek <jaroslav.dob...@gmail.com> wrote: > Hello, > > what is the most straightforward way to use a set of choices of which > several can be chosen without using a ManyToManyField? > > Using a ManyToManyField would make

Set of choices of which several can be chosen without using a ManyToManyField

2011-11-01 Thread Jaroslav Dobrek
Hello, what is the most straightforward way to use a set of choices of which several can be chosen without using a ManyToManyField? Using a ManyToManyField would make my program unnecessarily complicated. Example: class Candidate(models.Model): programming_languages

Re: Using datetime.time object in form field choices

2011-09-13 Thread josephi
gt; override the default field for start_time and use a ChoiceField with > choices set to something like this ((time(9), '9 am'), (time(10), '10 > am'), ...). > > This seems to work perfectly well, with the correct time values being > saved to the database. The only real reason I'm a

Using datetime.time object in form field choices

2011-09-13 Thread josephi
for start_time and use a ChoiceField with choices set to something like this ((time(9), '9 am'), (time(10), '10 am'), ...). This seems to work perfectly well, with the correct time values being saved to the database. The only real reason I'm asking this question is that I couldn't find any examples

Re: Limiting choices for inline manytomany field

2011-08-16 Thread DelS
= > Numerous clever workarounds are given in the forums but I decided to > try using "formfield_for_manytomany" in the inline class. This works > brilliantly. == Make that "...using formfield_for_foreignkey() in the inline class." !!! (Rushing to go for a coffee!) On Aug

Limiting choices for inline manytomany field

2011-08-15 Thread DelS
I am fairly new and using Django Admin to manage a set of lists and forms for a database GUI. I am not happy with the performance rendering a form which has foreignkey fields or manytomany fields with numerous values. This inspired me to get involved with overloading "formfield_for_foreignkey"

Re: Passing tuple values to a model choices field

2011-08-09 Thread Kayode Odeyemi
return u"%s | %s | %s" % ( > unicode(self.name_branch), > unicode(self.address_1)) > > class TransactionUpdateForm(forms.ModelForm): > branchqs = Branch.objects.get(name_branch) > branches_field = forms.BranchModelChoiceField(bran

Re: Passing tuple values to a model choices field

2011-08-08 Thread Kayode Odeyemi
rm): branchqs = Branch.objects.get(name_branch) branches_field = forms.BranchModelChoiceField(branchqs) #ModelChoiceField instance branch_name_new = forms.models.CharField(required=True, widget=forms.Select(choices={'BR_CODE1': 'HQ': 'Branch 2'})) class Meta:

Re: Passing tuple values to a model choices field

2011-08-08 Thread Tom Evans
On Mon, Aug 8, 2011 at 2:56 PM, Daniel Roseman wrote: > > I'm afraid it's really not clear what you're trying to do, or what the > problem is. > If the issue is that you have a field referring to a foreign key, and you > want to change what the values displayed in the

Re: Passing tuple values to a model choices field

2011-08-08 Thread Daniel Roseman
On Monday, 8 August 2011 13:06:51 UTC+1, Kayode Odeyemi wrote: > > That didn't help either. It still did not depict what I'm trying to do. > Those filters are for retrieving values set by a user. However, I tried the > code below which is to hard code the choices into th

Re: Passing tuple values to a model choices field

2011-08-08 Thread Kayode Odeyemi
e they do in the admin, right ? > > You might want to check Django's source for the admin forms and templates > to get some inspiration then. > > Hard coding the choices is never a satisfactory solution but I suggest you > retrieve them from your models file so you stay DRY complian

Re: Passing tuple values to a model choices field

2011-08-08 Thread Thomas Orozco
Like they do in the admin, right ? You might want to check Django's source for the admin forms and templates to get some inspiration then. Hard coding the choices is never a satisfactory solution but I suggest you retrieve them from your models file so you stay DRY compliant and then it's pretty

Re: Passing tuple values to a model choices field

2011-08-08 Thread Kayode Odeyemi
That didn't help either. It still did not depict what I'm trying to do. Those filters are for retrieving values set by a user. However, I tried the code below which is to hard code the choices into the form field on creation class TransactionUpdateForm(forms.ModelForm): branch_name_new

Re: Passing tuple values to a model choices field

2011-08-08 Thread Thomas Orozco
ext, > context_instance=RC(request)) > > At what point do I do: update_form.get_branch_name_display()? In forms.py or > views.py? Where? > > It seems to me that get_FOO_display() is meant to display the values set by > the user. This is not what I'm looking to do. What I got stuck with i

Re: Passing tuple values to a model choices field

2011-08-08 Thread Kayode Odeyemi
eems to me that get_FOO_display() is meant to display the values set by the user. This is not what I'm looking to do. What I got stuck with is that the tuple values are not displayed as options in the form select field(choices). Thanks On Mon, Aug 8, 2011 at 10:40 AM, Thomas Orozco <g.orozco.tho...@gm

Re: Passing tuple values to a model choices field

2011-08-08 Thread Thomas Orozco
; > from django.db import models > from django.forms import ModelForm > > TITLE_CHOICES = ( > ('MR', 'Mr.'), > ('MRS', 'Mrs.'), > ('MS', 'Ms.'), > ) > > class Author(models.Model): > name = models.CharField(max_length=100) > title = models.CharField(max_length=3, choi

Passing tuple values to a model choices field

2011-08-08 Thread Kayode Odeyemi
= models.CharField(max_length=100) title = models.CharField(max_length=3, choices=TITLE_CHOICES) birth_date = models.DateField(blank=True, null=True) def __unicode__(self): return self.name class AuthorForm(ModelForm): class Meta: model = Author I have got similar setup

Re: CharField with choices gets no ... choices

2011-05-12 Thread Thomas Weholt
On Thu, May 12, 2011 at 10:09 AM, Jani Tiainen <rede...@gmail.com> wrote: > On Thu, 2011-05-12 at 09:59 +0200, Thomas Weholt wrote: >> I got a model looking something like this >> >> class SomeModel(models.Model): >>     somefield = models.CharField(m

Re: CharField with choices gets no ... choices

2011-05-12 Thread Oleg Lomaka
You don't need to override choices for Model, because it is global to validate "what values accepted to store into database". It's not depends on current request scope or session. If you need to provide user with subset of choices to choose from dynamically, then you should

Re: CharField with choices gets no ... choices

2011-05-12 Thread Jani Tiainen
On Thu, 2011-05-12 at 09:59 +0200, Thomas Weholt wrote: > I got a model looking something like this > > class SomeModel(models.Model): > somefield = models.CharField(max_length=100, choices=somemethod()) > > The problem is that somemethod, which produces the choices to

CharField with choices gets no ... choices

2011-05-12 Thread Thomas Weholt
I got a model looking something like this class SomeModel(models.Model): somefield = models.CharField(max_length=100, choices=somemethod()) The problem is that somemethod, which produces the choices to give in the form in the admin, is called when the module is imported, not when the form

Using different choices in different ModelAdmins

2011-04-25 Thread Juan Pablo Romero Méndez
Hello, I'm developing several personalized admin sites (by subclassing admin.ModelAdmin). Is it possible to use different Field.choices in a particular field for each admin site? The problem is that the choices option is set within the model definition, not in the ModelAdmin. Regards, Juan

Re: Formset and Choices with Objects

2011-04-21 Thread Shawn Milochik
For the first question, you can use the form's 'instance' property to access the underlying model instance. For the latter, it sounds like you just need to concatenate the stuff you display. -- You received this message because you are subscribed to the Google Groups "Django users" group. To

Re: Formset and Choices with Objects

2011-04-21 Thread Dan Gentry
However, in order to display more detail in each row, I'd like to have > access to the object behind it - to reference columns not displayed, > follow foreign key relationships, etc., but I can't see how to do it. > Any advice? > > On the same form, I'd like a similar functionality for t

Formset and Choices with Objects

2011-04-21 Thread Dan Gentry
, etc., but I can't see how to do it. Any advice? On the same form, I'd like a similar functionality for the choices in a series of radio buttons. The choices attribute only accepts a list of two values - index and label. The design calls for several pieces of data (date, time, location

Re: limit_choices_to (or some other way) to filter ForeignKey choices based on current model field

2011-04-19 Thread Derek
x_length=255) >     mymodel = models.ForeignKey(MyModel) > > class MyModelItem(models.Model): >     mymodel = models.ForeignKey(MyModel) >     other = models.ForeignKey(OtherModel, null=True, blank=True) > === > > how can i use limit_choices_to (or some other way) to filte

limit_choices_to (or some other way) to filter ForeignKey choices based on current model field

2011-04-16 Thread Aljoša Mohorović
(MyModel) other = models.ForeignKey(OtherModel, null=True, blank=True) === how can i use limit_choices_to (or some other way) to filter ForeignKey choices based on current model field? basically, how can i do: other = models.ForeignKey(OtherModel, null=True, blank=True, limit_choices_to

Re: How to limit a ManyToManyField to three choices?

2011-03-12 Thread werefr0g
Well, MAX_CUISINES = 3 def clean(self): # three cuisines max. allowed if self.pk is None: # That's the case that raise the error # you're inserting a new Restaurant pass else: # Here, you're editing an existing Restaurant

Re: How to limit a ManyToManyField to three choices?

2011-03-12 Thread bagheera
Dnia 11-03-2011 o 22:45:34 greenie2600 napisał(a): 'Restaurant' instance needs to have a primary key value before a many- to-many relationship can be used. That is the answer You need to understand. afiak You can't perform m2m validation on model level due that very

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread greenie2600
werefr0g— Yep, that's actually the solution I'm looking into right now. However, I'm getting an error when trying to save a new instance of the Restaurant model: "'Restaurant' instance needs to have a primary key value before a many- to-many relationship can be used." Here's the new code that's

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread gontran
I didn't try it, but werefr0g may be right. It seems that Model.clean() is the method do you need. And you can still add a javascript control for more convenience without the risk that if a user deactivate javascript, the error will be saved. Let us know greenie if it's ok with this method.

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread werefr0g
Hello, Can Model.clean() method help you? [1] You'll still have to pay attention to validation before trying to save your instances.[2] Regards, [1] http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.clean [2]

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread bagheera
Dnia 11-03-2011 o 21:39:01 bagheera <neost...@go2.pl> napisał(a): Dnia 11-03-2011 o 21:29:29 greenie2600 <greenie2...@gmail.com> napisał(a): bagheera - I had seen the limit_choices_to parameter, but I thought it controlled *which* choices are available to the user - not *how m

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread bagheera
Dnia 11-03-2011 o 21:29:29 greenie2600 <greenie2...@gmail.com> napisał(a): bagheera - I had seen the limit_choices_to parameter, but I thought it controlled *which* choices are available to the user - not *how many* they're allowed to choose. I want to show the user a list of 20

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread bagheera
Dnia 11-03-2011 o 21:29:29 greenie2600 <greenie2...@gmail.com> napisał(a): bagheera - I had seen the limit_choices_to parameter, but I thought it controlled *which* choices are available to the user - not *how many* they're allowed to choose. I want to show the user a list of 20

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread bagheera
valid; it just wasn't saved). I think I need to override the model validation instead. Perhaps I need to override Model.clean_fields()? Right, i just get to that point, there is a cave rat about limiting choices on form level. Depending on limiting query it may make problems if you edit this

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread greenie2600
bagheera - I had seen the limit_choices_to parameter, but I thought it controlled *which* choices are available to the user - not *how many* they're allowed to choose. I want to show the user a list of 20 or 30 cuisines, but forbid them from checking more than three. Can you show me an example

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread greenie2600
gontran - Thanks. However, I tried the sample code in your link, and I don't think it will work. Returning a string from the overridden save() method prevents the record from being saved to the database, but by the time the save() method is invoked, my ModelForm (and consequently, I presume, the

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread bagheera
n't be able to check a fourth box. My question: can this be enforced within the model, or is this something I'd have to build into my interface layer? You can limit choices on model level: http://docs.djangoproject.com/en/1.2/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to If que

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread gontran
edit: you don't need to raise an error if the restaurant already has 3 Cuisine's objects associated, you just need to return a string with the explanation of the error. On 11 mar, 20:11, gontran wrote: > Hi greenie, > > you just need to override the save method from

Re: How to limit a ManyToManyField to three choices?

2011-03-11 Thread gontran
Hi greenie, you just need to override the save method from your model Restaurant. Before saving each instance, you check if the restaurant already has 3 Cuisine's objects associated. If yes, you don't save the instance and raise an error for exemple, if no, just call the standard method of the

How to limit a ManyToManyField to three choices?

2011-03-11 Thread greenie2600
Hi all - I have two models with a many-to-many relationship: Restaurant and Cuisine. The Cuisine table contains, e.g., "Italian", "Mexican", "Chinese", etc. Each Restaurant record can be associated with one or more Cuisines. Here's the thing: I'd like to limit this to three Cuisines per

Re: field choices() as queryset?

2011-02-24 Thread galago
I think it works. Thanks. What I did: changed the form cal in view: form_provinces_to_add = ProvinceForm(request.POST, user=request.user) changed a form a little: class ProvinceForm(ModelForm): def __init__(self, *args, **kwargs): self.user = kwargs.pop('user')

Re: field choices() as queryset?

2011-02-24 Thread Tom Evans
On Thu, Feb 24, 2011 at 2:17 PM, galago wrote: > Now I have some strange thing. I display my form, send post and try to save > it. But it doesn't save:/ > Here's my code: > model: > class UserProvince(models.Model): >     user = models.ForeignKey(User) >     province =

Re: field choices() as queryset?

2011-02-24 Thread galago
Now I have some strange thing. I display my form, send post and try to save it. But it doesn't save:/ Here's my code: model: class UserProvince(models.Model): user = models.ForeignKey(User) province = models.ForeignKey(Province) class Meta: unique_together = (('user',

Re: field choices() as queryset?

2011-02-24 Thread Mike Ramirez
On Thursday, February 24, 2011 05:15:09 am Tom Evans wrote: > Cargo cult programming is bad. > > Cheers > > Tom Not going to really argue the point, it's valid, but it could be based on habits taught by others, mentors... Mike -- Never, ever lie to someone you love unless you're absolutely

Re: field choices() as queryset?

2011-02-24 Thread Tom Evans
On Thu, Feb 24, 2011 at 1:07 PM, Mike Ramirez wrote: > On Thursday, February 24, 2011 05:00:23 am galago wrote: >> class ProvinceForm(ModelForm): > >> def __init__(self, *args, **kwargs): >> > > for self.instance, you'll wnat to do something like this: > > self.instance =

Re: field choices() as queryset?

2011-02-24 Thread Mike Ramirez
user_provinces = > UserProvince.objects.select_related().filter(user__exact=self.instance.id). > values_list('province') self.fields['name'].choices = > Province.objects.exclude(id__in=user_provinces).values_list('id', 'name') > > class Meta: > model = Province >

Re: field choices() as queryset?

2011-02-24 Thread galago
hmm, that solutoin works great:) class ProvinceForm(ModelForm): def __init__(self, *args, **kwargs): super(ProvinceForm, self).__init__(*args, **kwargs) user_provinces = UserProvince.objects.select_related().filter(user__exact=self.instance.id).values_list('province')

Re: field choices() as queryset?

2011-02-24 Thread galago
('province') self.fields['name'].choices = Province.objects.exclude(id__in=user_provinces).values_list('id', 'name') class Meta: model = Province fields = ('name',) widgets = { 'name': Select(), } -- You received this message because you

Re: field choices() as queryset?

2011-02-24 Thread Mike Ramirez
On Thursday, February 24, 2011 04:21:46 am galago wrote: > Thanks, that's the way I'll do it:) > But now I have 1 more problem. In ModelForm I want to get some data about > user from DB. I nedd to filter user provinces. How canI call the user id > in my query? I pass request.user as form instance

RE: field choices() as queryset?

2011-02-24 Thread Chris Matthews
Typo choices.append((item.name, item.name)) should be choices.append((item.id, item.name)) From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Mike Ramirez Sent: 24 February 2011 14:10 To: django-users@googlegroups.com Subject: Re: field choices() as queryset

Re: field choices() as queryset?

2011-02-24 Thread galago
Thanks, that's the way I'll do it:) But now I have 1 more problem. In ModelForm I want to get some data about user from DB. I nedd to filter user provinces. How canI call the user id in my query? I pass request.user as form instance in view: form = ProvinceForm(instance=request.user) How to

Re: field choices() as queryset?

2011-02-24 Thread Mike Ramirez
= models.SlugField(max_length=30) > > def __unicode__(self): > return self.name > > It's rows to this are added only by admin, but all users can see it in > forms. > I want to make a ModelForm from that. I made something like this: > class ProvinceForm(Model

field choices() as queryset?

2011-02-24 Thread galago
rows to this are added only by admin, but all users can see it in forms. I want to make a ModelForm from that. I made something like this: class ProvinceForm(ModelForm): class Meta: CHOICES = Province.objects.all() model = Province fields = ('name',) widgets

Re: Change null representation when you're using choices widget.

2011-02-04 Thread Marc Aymerich
On Fri, Feb 4, 2011 at 3:37 PM, Marcos Moyano <marcosmoy...@gmail.com> wrote: > Remove (None, "No Period") from your choices and left the required=False on > your form field. That should work. > but I wanted to do was to change the default value of null value: instead o

Re: Change null representation when you're using choices widget.

2011-02-04 Thread Marcos Moyano
s/left/leave/ sorry fot the double post. On Fri, Feb 4, 2011 at 11:37 AM, Marcos Moyano <marcosmoy...@gmail.com>wrote: > Remove (None, "No Period") from your choices and left the required=False on > your form field. That should work. > > Rgds, > Marcos > > &g

Re: Change null representation when you're using choices widget.

2011-02-04 Thread Marc Aymerich
On Fri, Feb 4, 2011 at 3:31 PM, Marc Aymerich <glicer...@gmail.com> wrote: > On Fri, Feb 4, 2011 at 12:12 PM, Tom Evans <tevans...@googlemail.com> wrote: >> On Fri, Feb 4, 2011 at 11:07 AM, Marc Aymerich <glicer...@gmail.com> wrote: >>> Hi >>> In

Re: Change null representation when you're using choices widget.

2011-02-04 Thread Marcos Moyano
Remove (None, "No Period") from your choices and left the required=False on your form field. That should work. Rgds, Marcos On Fri, Feb 4, 2011 at 11:31 AM, Marc Aymerich <glicer...@gmail.com> wrote: > On Fri, Feb 4, 2011 at 12:12 PM, Tom Evans <tevans...@googlemail.co

Re: Change null representation when you're using choices widget.

2011-02-04 Thread Marc Aymerich
On Fri, Feb 4, 2011 at 12:12 PM, Tom Evans <tevans...@googlemail.com> wrote: > On Fri, Feb 4, 2011 at 11:07 AM, Marc Aymerich <glicer...@gmail.com> wrote: >> Hi >> In some choices widgets I want to represent null values as u'No >> period' i

Re: Change null representation when you're using choices widget.

2011-02-04 Thread Tom Evans
On Fri, Feb 4, 2011 at 11:07 AM, Marc Aymerich <glicer...@gmail.com> wrote: > Hi > In some choices widgets I want to represent null values as u'No > period' instead of u'' > > I try with: > > PERIOD_CHOICES = getatt

Change null representation when you're using choices widget.

2011-02-04 Thread Marc Aymerich
Hi In some choices widgets I want to represent null values as u'No period' instead of u'' I try with: PERIOD_CHOICES = getattr(settings, 'PERIOD_CHOICES', ((None, ugettext('No Period

Re: Does anyone knows how to modify choices option of a fields from __init__(self,)?

2011-01-27 Thread Shawn Milochik
In your __init__, after the super().__init__(): self.fields['state_province'].choices = dynamic_options Shawn -- 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 u

Does anyone knows how to modify choices option of a fields from __init__(self,)?

2011-01-27 Thread cocobuster
Hi, I have been trying to dynamically change CHOICES options of a fields, which is modified inside the __init__(self,) of my model class. I can see my choices being modified in the __init__(self,), BUT using a modelform the final result is NOT considering the dynamic changed CHOICES. Does

ModelForm and checkbox from choices

2010-12-30 Thread robos85
In my model i have that part: ... STATUSES_CHOICES = ( (0, _(u'one')), (1, _(u'two')), (2, _(u'three')) ) ... status = models.SmallIntegerField(default=0, choices=STATUSES_CHOICES, null=True, blank=True) then in my form based on that model I wanto to make

Re: how to define choices option per model's instance

2010-12-03 Thread Cal Leeming [Simplicity Media Ltd]
. For example, rather than restricting this at the option level, perhaps override the save() and add in some custom checking there. Athough the below code segment isn't perfect, it might be a good starting ground. class Something(models.Model): range_marks = models.IntegerField(choices

Re: how to define choices option per model's instance

2010-12-02 Thread adj7388
) self.organization = organization if self.organization: account_entry_types = AccountEntryType.objects.filter(organization=self.organization) self.fields['account_entry_type'].choices = [('', '---')] self.fields['account_entry_type'].choices.extend([(aet.id

Re: how to define choices option per model's instance

2010-12-02 Thread Alex Boyko
Hi Cal! Thank you very much for your reply and advice, but unfortunately it doesn't work. It seems like in __init__ method we can't re-assign the choices. Even if I try: class Something(models.Model): def __init__(self, *args, **kwargs): _choices = ((SomeValue, 'SomeString

Re: how to define choices option per model's instance

2010-12-02 Thread Cal Leeming [Simplicity Media Ltd]
= (('default', 'default'), ) self.range_marks = models.IntegerField(choices = _choices, verbose_name = 'Marks of Something') super(Something, self).__init__(*args, **kwargs) Let us know if it works :) Cheers Cal On 02/12/2010 06:53, Alex Boyko wrote: Hi! I got such kind

how to define choices option per model's instance

2010-12-01 Thread Alex Boyko
Hi! I got such kind of problem. I'd like to define the tuple(list) of choices option at the moment of instance created on the fly In the future these choices will not change. Hence I've found just one way to do it - override __init__() of my model and pass there the particular predefined list

Re: Choices vs. ForeignKeys

2010-11-30 Thread Torsten Bronger
Hallöchen! Todd Wilson writes: > [...] > > [...] Instead of hard-coding the entity types here, you are using > a constant, presumably because you may want to introduce more > entity types later. But what are the trade-offs bewteen > representing types as CharFields wi

Choices vs. ForeignKeys (was: Django - Alternative to using NULLs? (for integer and FK fields).)

2010-11-29 Thread Todd Wilson
relationship of interest. > > Hope this helps ... > > class Entity(models.Model): > """ > Entities can be corporations or humans. entity_type indicates > which. > """ > entity_type = models.CharField(max_lengt

Re: django tagging app choices

2010-11-16 Thread Scot Hacker
On Nov 15, 8:55 pm, Thomas Schreiber wrote: > check the grids on django packages:http://djangopackages.com/grids/g/tagging/ django-taggit seems to be the new hotness. Unfortunately we've been waiting for months for a conversion script to help us migrate from django-tagging to

Re: django tagging app choices

2010-11-15 Thread Thomas Schreiber
check the grids on django packages: http://djangopackages.com/grids/g/tagging/ On Mon, Nov 15, 2010 at 22:22, gyanguru wrote: > Hi all, > > I am looking for django tag project. I have discovered 2 "django > tagging" and "django tagit". > Does any one has a benchmark regarding

django tagging app choices

2010-11-15 Thread gyanguru
Hi all, I am looking for django tag project. I have discovered 2 "django tagging" and "django tagit". Does any one has a benchmark regarding this? or Any advice on which tagging app should I use. My use case requires less amount of unique tags compared to number of items to be tagged. Cheers

Re: Model field choices

2010-09-28 Thread Derek
Thanks, Steve. Sounds like a plan. On Sep 28, 10:48 pm, Steve Holden <holden...@gmail.com> wrote: > On 9/28/2010 10:39 PM, Derek wrote: > > > I have a model which has choices specified for the "offer_type" field: > > > class Coupon(models.Model): >

Re: Model field choices

2010-09-28 Thread Steve Holden
On 9/28/2010 10:39 PM, Derek wrote: > I have a model which has choices specified for the "offer_type" field: > > class Coupon(models.Model): > offer_types = ( > (1, 'Percentage Off'), > (2, 'Amount Off'), > (3, 'Free')

Model field choices

2010-09-28 Thread Derek
I have a model which has choices specified for the "offer_type" field: class Coupon(models.Model): offer_types = ( (1, 'Percentage Off'), (2, 'Amount Off'), (3, 'Free'), ) business = models.ForeignKe

Re: How do you set choices in your application?

2010-09-25 Thread werefr0g
with a field called "status". I could set the choices in three ways: 1) status_choices = ((1, 'Completed'), (2, 'Unfinished'), (3, 'Cancelled')) 2) status_choices = (('COM', 'Completed'), ('UNF', 'Unfinished'), ('CAN', 'Cancelled')) Or, 3 ): db_choices = Choice.objects.all(

Re: How do you set choices in your application?

2010-09-24 Thread Russell Keith-Magee
On Sat, Sep 25, 2010 at 10:50 AM, Yo-Yo Ma wrote: > Anyone have any thoughts. Yes. My thought is that you should settle down. This is a mailing list, populated by an international audience. You've waited less than *2 hours* before pinging the list for a response. This

Re: How do you set choices in your application?

2010-09-24 Thread Yo-Yo Ma
Anyone have any thoughts. -- 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

How do you set choices in your application?

2010-09-24 Thread Yo-Yo Ma
Let's say I have a model with a field called "status". I could set the choices in three ways: 1) status_choices = ((1, 'Completed'), (2, 'Unfinished'), (3, 'Cancelled')) 2) status_choices = (('COM', 'Completed'), ('UNF', 'Unfinished'), ('CAN', 'Cancelled')) Or, 3 ):

Re: ModelMultipleChoiceField queryset argument does not limit widget choices

2010-09-14 Thread The Boss
> I generally do something like: > > class OrderForm(ModelForm): >     def __init__(self, *args, **kw): >         ordernumber = '%06d' % kw.pop('ordernumber', 0) >         super(OrderForm, self).__init__(*args, **kw) >         self.fields['associated_files'].queryset = >            

filling model choices field according to language code

2010-08-30 Thread Oguz Yarimtepe
'), #edit begins choices=((0,""),), #edit begins

Re: ModelMultipleChoiceField queryset argument does not limit widget choices

2010-08-27 Thread Karen Tracey
On Thu, Aug 26, 2010 at 11:09 PM, The Boss wrote: > This should really be much easier. I generally do something like: class OrderForm(ModelForm): def __init__(self, *args, **kw): ordernumber = '%06d' % kw.pop('ordernumber', 0) super(OrderForm,

Re: ModelMultipleChoiceField queryset argument does not limit widget choices

2010-08-26 Thread The Boss
Ok, I sort of found a solution. After much digging and looking at class dictionaries I found that i could manually update the dictionary self.base_fields. self.base_fields['associated_files'] =self.__class__.associated_files It's seems that class attrs assigned in init do not get added

ModelMultipleChoiceField queryset argument does not limit widget choices

2010-08-26 Thread The Boss
The documentation made this seem trivial but I must be missing something. I have an order form with a many to many field to ArchivedFiles. I want to just show file choices that start with the order number given to the form at instantiation. I almost works. class OrderForm(ModelForm): def

Re: Loop over a form's choices (radio button) and render it

2010-08-24 Thread pravasi
t. > How would I do that? Just referring to > {{ selectform.fields.selectfield.choices }} in the template gives me > the list of choices (i.e. each single choice when I loop over it), but > not the html I want. > > Are there any other approaches to the problem? > > Thanks for your

Re: Loop over a form's choices (radio button) and render it

2010-08-23 Thread Bill Freeman
Andreas, I'll give it a try, but it won't be soon. Other projects are hot. Bill On Sun, Aug 22, 2010 at 9:07 AM, Andreas Pfrengle wrote: > Hello Bill, > > thanks for the code. It took half the weekend, but finally I built > upon this to get a radiobutton-iterator. This

Re: Loop over a form's choices (radio button) and render it

2010-08-22 Thread Andreas Pfrengle
Hello Bill, thanks for the code. It took half the weekend, but finally I built upon this to get a radiobutton-iterator. This was a bit more complicated, since the RadioInput widget has no own render-method, so I needed to introduce a helper class that derives from RadioInput. I've put the code

Re: Validation and dynamically extending ChoiceField choices

2010-08-17 Thread ringemup
Oh, that sounds like a great way to handle it. Thank you! On Aug 17, 10:10 am, Alex Robbins <alexander.j.robb...@gmail.com> wrote: > Maybe the ChoiceField should just be a CharField that just uses the > Select widget class? That way it won't have choices hardcoded into the > f

Re: Validation and dynamically extending ChoiceField choices

2010-08-17 Thread Alex Robbins
Maybe the ChoiceField should just be a CharField that just uses the Select widget class? That way it won't have choices hardcoded into the field validation. Your clean method could check that the domain is valid. Alex On Aug 16, 1:39 pm, ringemup <ringe...@gmail.com> wrote: > I have

Re: Loop over a form's choices (radio button) and render it

2010-08-16 Thread Bill Freeman
Ok. I have permission from my boss, and have cleaned it up a bit. See: http://djangosnippets.org/snippets/2151/ Bill On Sat, Aug 14, 2010 at 7:25 AM, Andreas Pfrengle wrote: > Hello Bill, > > thanks for your answer. However, I've never written a template filter > yet.

Validation and dynamically extending ChoiceField choices

2010-08-16 Thread ringemup
. Subsequently, the user may either enter a new list of domains to check, or select a domain from the radio buttons. However, when they select one of the radio buttons, the form never validates because the selected domain "is not one of the available choices" -- because, of course, t

<    1   2   3   4   5   6   7   8   9   >