Re: Drop Down Menu in Django Forms not working.
class EvalState(models.Model,AtlasBaseHelper): """ Represents Eval State: ACTIVE INACTIVE DELETE NA """ name = models.CharField(max_length=32, unique=True) friendly_name = models.CharField(max_length=32, unique=True) description = models.CharField(max_length=255, blank=True, null=True) class Meta: verbose_name = "Eval States" def __unicode__(self): return self.name class Bundle(AtlasAuditModel, AtlasBaseHelper):^M """^M Represents the bundle purchased by the customer. The bundle^M contains a reference identifier which remains the same if the^M the bundle is either upgraded or entended.^M A bundle can have 0 or more features.^M """^M bundle_id = models.CharField(verbose_name="Bundle ID",^M max_length=32,^M unique=True)^M customer = models.ForeignKey(Customer)^M description = models.CharField(max_length=255, blank=True, null=True)^M state = models.ForeignKey(BundleState)^M extended_state = models.ForeignKey(BundleExtendedState)^M type = models.ForeignKey(BundleType)^M quantity = models.FloatField(blank=False)^M start_date = models.DateField(verbose_name="Start Date")^M end_date = models.DateField(verbose_name="End Date")^M stage = models.CharField(max_length=32, blank=True, null=True)^M *stage_state = models.ForeignKey(EvalState, verbose_name="Eval State", null=True)* The Below is the Migration Script written to add the States in to EvalState: def forwards(apps, schema_editor): DcPropertyType = apps.get_model("atlas", "evalstate") db_alias = schema_editor.connection.alias DcPropertyType.objects.using(db_alias).bulk_create([ DcPropertyType(name="ACTIVE", friendly_name="EVAL Active", description="Bundle EVAL State is ACTIVE"), DcPropertyType(name="INACTIVE", friendly_name="EVAL InActive",description="Bundle EVAL state is INACTIVE"), DcPropertyType(name="DELETE", friendly_name="EVAL Delete", description="Bundle EVAL state is DELETE"), DcPropertyType(name="NA", friendly_name="EVAL NotApplicable", description="Bundle EVAL state is not applicable") ]) def backwards(apps, schema_editor): DcPropertyType = apps.get_model("atlas", "evalstate") db_alias = schema_editor.connection.alias DcPropertyType.objects.using(db_alias).filter(name="ACTIVE", description="Bundle EVAL State is ACTIVE").delete() DcPropertyType.objects.using(db_alias).filter(name="INACTIVE", description="Bundle EVAL state is INACTIVE").delete() DcPropertyType.objects.using(db_alias).filter(name="DELETE", description="Bundle EVAL state is DELETE").delete() DcPropertyType.objects.using(db_alias).filter(name="NA", description="Bundle EVAL state is not applicable").delete() class Migration(migrations.Migration): dependencies = [ ('atlas', '0012_add_eval_states'), ] operations = [ migrations.RunPython(forwards, backwards), ] Does this make sense for the model structure. I do not have any Models Diagram for the same. --- Arun On Monday, August 7, 2017 at 4:13:33 PM UTC+5:30, lemme smash wrote: > > you didn't show me a model structure, you just showed another model, so I > can't give you example without picture of what's going on there > > On Monday, August 7, 2017 at 1:39:49 PM UTC+3, Arun S wrote: >> >> Can you just give an Example for this taking a Query. >> >> >> >> On Monday, August 7, 2017 at 3:37:04 PM UTC+5:30, lemme smash wrote: >>> >>> i meant EvalState model >>> if name attribute on it is a ForeignKey you should get corresponding >>> queryset of model it links to >>> if it's charfield, you should use text choices >>> >>> On Monday, August 7, 2017 at 6:22:50 AM UTC+3, Arun S wrote: The Models Look like this : stage_state = models.ForeignKey(EvalState, verbose_name="Eval State") class Bundle(AtlasAuditModel, AtlasBaseHelper):^M """^M Represents the bundle purchased by the customer. The bundle^M contains a reference identifier which remains the same if the^M the bundle is either upgraded or entended.^M A bundle can have 0 or more features.^M """^M bundle_id = models.CharField(verbose_name="Bundle ID",^M max_length=32,^M unique=True)^M stage_state = models.ForeignKey(*EvalState*, verbose_name="Eval State") atlas_bundle; atlas_bundle | CREATE TABLE `atlas_bundle` ( `id` int(11) NOT NULL AUTO_INCREMENT, ... ... *`stage_state_id` int(11) NOT NULL,* PRIMARY KEY (`id`), *KEY `atlas_bundle_36c1765e` (`stage_state_id`)* ) ENGINE=InnoDB AUTO_INCREMENT=1408 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC | 19 rows in set (0.01 sec) desc
Re: Drop Down Menu in Django Forms not working.
you didn't show me a model structure, you just showed another model, so I can't give you example without picture of what's going on there On Monday, August 7, 2017 at 1:39:49 PM UTC+3, Arun S wrote: > > Can you just give an Example for this taking a Query. > > > > On Monday, August 7, 2017 at 3:37:04 PM UTC+5:30, lemme smash wrote: >> >> i meant EvalState model >> if name attribute on it is a ForeignKey you should get corresponding >> queryset of model it links to >> if it's charfield, you should use text choices >> >> On Monday, August 7, 2017 at 6:22:50 AM UTC+3, Arun S wrote: >>> >>> The Models Look like this : >>> >>> stage_state = models.ForeignKey(EvalState, verbose_name="Eval State") >>> class Bundle(AtlasAuditModel, AtlasBaseHelper):^M >>> """^M >>> Represents the bundle purchased by the customer. The bundle^M >>> contains a reference identifier which remains the same if the^M >>> the bundle is either upgraded or entended.^M >>> A bundle can have 0 or more features.^M >>> """^M >>> bundle_id = models.CharField(verbose_name="Bundle ID",^M >>> max_length=32,^M >>> unique=True)^M >>> >>> >>> >>> stage_state = models.ForeignKey(*EvalState*, verbose_name="Eval >>> State") >>> >>> >>> atlas_bundle; >>> atlas_bundle | CREATE TABLE `atlas_bundle` ( >>> `id` int(11) NOT NULL AUTO_INCREMENT, >>> ... >>> >>> ... >>> *`stage_state_id` int(11) NOT NULL,* >>> PRIMARY KEY (`id`), >>> *KEY `atlas_bundle_36c1765e` (`stage_state_id`)* >>> ) ENGINE=InnoDB AUTO_INCREMENT=1408 DEFAULT CHARSET=latin1 >>> ROW_FORMAT=DYNAMIC | >>> 19 rows in set (0.01 sec) >>> >>> desc *evalstate*; >>> +---+--+--+-+-++ >>> | Field | Type | Null | Key | Default | Extra | >>> +---+--+--+-+-++ >>> | id| int(11) | NO | PRI | NULL| auto_increment | >>> | name | varchar(32) | NO | UNI | NULL|| >>> | friendly_name | varchar(32) | NO | UNI | NULL|| >>> | description | varchar(255) | YES | | NULL|| >>> +---+--+--+-+-++ >>> 4 rows in set (0.00 sec) >>> >>> Whats the Difference in having qs when there is a foriegn Key value? >>> >>> Arun >>> >>> On Sunday, August 6, 2017 at 7:48:11 PM UTC+5:30, lemme smash wrote: so, you can maybe show you models structure here? also, if it is a ForeignKey, why you trying to filter qs by string values? I mean Q(name = 'ACTIVE') it's shouldn't work On Sunday, August 6, 2017 at 5:22:21 AM UTC+3, Arun S wrote: > > Yes, name is a foreign key here. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f0016136-3478-4af3-8509-28b964397090%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Drop Down Menu in Django Forms not working.
Can you just give an Example for this taking a Query. On Monday, August 7, 2017 at 3:37:04 PM UTC+5:30, lemme smash wrote: > > i meant EvalState model > if name attribute on it is a ForeignKey you should get corresponding > queryset of model it links to > if it's charfield, you should use text choices > > On Monday, August 7, 2017 at 6:22:50 AM UTC+3, Arun S wrote: >> >> The Models Look like this : >> >> stage_state = models.ForeignKey(EvalState, verbose_name="Eval State") >> class Bundle(AtlasAuditModel, AtlasBaseHelper):^M >> """^M >> Represents the bundle purchased by the customer. The bundle^M >> contains a reference identifier which remains the same if the^M >> the bundle is either upgraded or entended.^M >> A bundle can have 0 or more features.^M >> """^M >> bundle_id = models.CharField(verbose_name="Bundle ID",^M >> max_length=32,^M >> unique=True)^M >> >> >> >> stage_state = models.ForeignKey(*EvalState*, verbose_name="Eval >> State") >> >> >> atlas_bundle; >> atlas_bundle | CREATE TABLE `atlas_bundle` ( >> `id` int(11) NOT NULL AUTO_INCREMENT, >> ... >> >> ... >> *`stage_state_id` int(11) NOT NULL,* >> PRIMARY KEY (`id`), >> *KEY `atlas_bundle_36c1765e` (`stage_state_id`)* >> ) ENGINE=InnoDB AUTO_INCREMENT=1408 DEFAULT CHARSET=latin1 >> ROW_FORMAT=DYNAMIC | >> 19 rows in set (0.01 sec) >> >> desc *evalstate*; >> +---+--+--+-+-++ >> | Field | Type | Null | Key | Default | Extra | >> +---+--+--+-+-++ >> | id| int(11) | NO | PRI | NULL| auto_increment | >> | name | varchar(32) | NO | UNI | NULL|| >> | friendly_name | varchar(32) | NO | UNI | NULL|| >> | description | varchar(255) | YES | | NULL|| >> +---+--+--+-+-++ >> 4 rows in set (0.00 sec) >> >> Whats the Difference in having qs when there is a foriegn Key value? >> >> Arun >> >> On Sunday, August 6, 2017 at 7:48:11 PM UTC+5:30, lemme smash wrote: >>> >>> so, you can maybe show you models structure here? >>> also, if it is a ForeignKey, why you trying to filter qs by string >>> values? I mean Q(name = 'ACTIVE') >>> it's shouldn't work >>> >>> >>> On Sunday, August 6, 2017 at 5:22:21 AM UTC+3, Arun S wrote: Yes, name is a foreign key here. >>> >>> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f2c6ca98-9393-4e80-a303-ede320feddd9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Drop Down Menu in Django Forms not working.
i meant EvalState model if name attribute on it is a ForeignKey you should get corresponding queryset of model it links to if it's charfield, you should use text choices On Monday, August 7, 2017 at 6:22:50 AM UTC+3, Arun S wrote: > > The Models Look like this : > > stage_state = models.ForeignKey(EvalState, verbose_name="Eval State") > class Bundle(AtlasAuditModel, AtlasBaseHelper):^M > """^M > Represents the bundle purchased by the customer. The bundle^M > contains a reference identifier which remains the same if the^M > the bundle is either upgraded or entended.^M > A bundle can have 0 or more features.^M > """^M > bundle_id = models.CharField(verbose_name="Bundle ID",^M > max_length=32,^M > unique=True)^M > > > > stage_state = models.ForeignKey(*EvalState*, verbose_name="Eval > State") > > > atlas_bundle; > atlas_bundle | CREATE TABLE `atlas_bundle` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > ... > > ... > *`stage_state_id` int(11) NOT NULL,* > PRIMARY KEY (`id`), > *KEY `atlas_bundle_36c1765e` (`stage_state_id`)* > ) ENGINE=InnoDB AUTO_INCREMENT=1408 DEFAULT CHARSET=latin1 > ROW_FORMAT=DYNAMIC | > 19 rows in set (0.01 sec) > > desc *evalstate*; > +---+--+--+-+-++ > | Field | Type | Null | Key | Default | Extra | > +---+--+--+-+-++ > | id| int(11) | NO | PRI | NULL| auto_increment | > | name | varchar(32) | NO | UNI | NULL|| > | friendly_name | varchar(32) | NO | UNI | NULL|| > | description | varchar(255) | YES | | NULL|| > +---+--+--+-+-++ > 4 rows in set (0.00 sec) > > Whats the Difference in having qs when there is a foriegn Key value? > > Arun > > On Sunday, August 6, 2017 at 7:48:11 PM UTC+5:30, lemme smash wrote: >> >> so, you can maybe show you models structure here? >> also, if it is a ForeignKey, why you trying to filter qs by string >> values? I mean Q(name = 'ACTIVE') >> it's shouldn't work >> >> >> On Sunday, August 6, 2017 at 5:22:21 AM UTC+3, Arun S wrote: >>> >>> Yes, name is a foreign key here. >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/acdd7ce3-0b42-4808-a6de-f6023ca3275f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Drop Down Menu in Django Forms not working.
The Models Look like this : stage_state = models.ForeignKey(EvalState, verbose_name="Eval State") class Bundle(AtlasAuditModel, AtlasBaseHelper):^M """^M Represents the bundle purchased by the customer. The bundle^M contains a reference identifier which remains the same if the^M the bundle is either upgraded or entended.^M A bundle can have 0 or more features.^M """^M bundle_id = models.CharField(verbose_name="Bundle ID",^M max_length=32,^M unique=True)^M stage_state = models.ForeignKey(*EvalState*, verbose_name="Eval State") atlas_bundle; atlas_bundle | CREATE TABLE `atlas_bundle` ( `id` int(11) NOT NULL AUTO_INCREMENT, ... ... *`stage_state_id` int(11) NOT NULL,* PRIMARY KEY (`id`), *KEY `atlas_bundle_36c1765e` (`stage_state_id`)* ) ENGINE=InnoDB AUTO_INCREMENT=1408 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC | 19 rows in set (0.01 sec) desc *evalstate*; +---+--+--+-+-++ | Field | Type | Null | Key | Default | Extra | +---+--+--+-+-++ | id| int(11) | NO | PRI | NULL| auto_increment | | name | varchar(32) | NO | UNI | NULL|| | friendly_name | varchar(32) | NO | UNI | NULL|| | description | varchar(255) | YES | | NULL|| +---+--+--+-+-++ 4 rows in set (0.00 sec) Whats the Difference in having qs when there is a foriegn Key value? Arun On Sunday, August 6, 2017 at 7:48:11 PM UTC+5:30, lemme smash wrote: > > so, you can maybe show you models structure here? > also, if it is a ForeignKey, why you trying to filter qs by string values? > I mean Q(name = 'ACTIVE') > it's shouldn't work > > > On Sunday, August 6, 2017 at 5:22:21 AM UTC+3, Arun S wrote: >> >> Yes, name is a foreign key here. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6a5277c8-a8f0-450f-b214-8cc251cab305%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Drop Down Menu in Django Forms not working.
so, you can maybe show you models structure here? also, if it is a ForeignKey, why you trying to filter qs by string values? I mean Q(name = 'ACTIVE') it's shouldn't work On Sunday, August 6, 2017 at 5:22:21 AM UTC+3, Arun S wrote: > > Yes, name is a foreign key here. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/34570842-a7f9-4043-8bfc-a1a893a71020%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Drop Down Menu in Django Forms not working.
Yes, name is a foreign key here. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4015cb08-4413-4a6d-90b6-219bc1b71d2a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Drop Down Menu in Django Forms not working.
name is a ForeignKey field? If not, you shouldn't use queryset attribute there. Use choices instead. If you want to render all available choices from db, you can get it like Model.objects.filter(...).values_list('name', flat=True) On Friday, August 4, 2017 at 8:07:24 PM UTC+3, Arun S wrote: > > Hi, > > I am trying to have a drop down menu for a field in my form but seems like > its not working as required. > > This is my form: forms.py > > eval_states = [ > ('ACTIVE',EvalState.objects.filter(name='ACTIVE')), > ('INACTIVE',EvalState.objects.filter(name='INACTIVE')), > ('DELETE',EvalState.objects.filter(name='DELETE')), > ] > > class EvalForm(forms.ModelForm): > def __init__(self, *args, **kwargs): > super(EvalForm, self).__init__(*args, **kwargs) > self.fields['name'].queryset = EvalState.objects.filter( > Q(name = 'ACTIVE') | Q(name = 'INACTIVE') | Q(name = > 'DELETE')) > > class Meta: > model = EvalState > fields = ('name',) > > my html : abc.html > > {% csrf_token %} > > > Eval State: > > {{ eval_form.name }} > > > > > > > view.py > eval_form = None > eval_form = atlas_forms.EvalForm(request.POST, EvalState) > if eval_form.is_valid(): > print eval_form.errors > eval_form.save() > else: > print eval_form.errors > > > What am i missing? > Basically requirement is that, i would need a drop down in the HTML and > whenever the Value is set and saved, I want it to be updated in the DB. > But i am not able to get through the first step of getting the options in > the HTML. > > Any Help on this would be great. > > Thanks > cheers > Arun. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/569250aa-3644-47b6-a952-e857247e966b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.