Re: Make a model form field not required
Works like a charm, but I don't completely understand why that is necessary. When I defined the text input as hidden and disabled, it overwrote the initial settings of that field? what exactly does this line do? def __init__(self, *args, **kwargs): forms.ModelForm.__init__(self, *args, **kwargs) -- 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/c0f916b2-9ee8-4b79-9126-5265566a5625%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Make a model form field not required
Hi, I am having some issues with making my form/model fields not required. Currently this is the code that I have: forms.py: class startRound(forms.ModelForm): player_2 = forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_2'})) player_3 = forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_3'})) player_4 = forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_4'})) class Meta: model = parentRounds models.py class parentRounds(models.Model): Name = models.CharField(max_length=200) player_1 = models.CharField(max_length=25) player_2 = models.CharField(max_length=25, null=True, blank=True) player_3 = models.CharField(max_length=25, null=True, blank=True) player_4 = models.CharField(max_length=25, null=True, blank=True) started_on = models.DateTimeField(auto_now_add=True) completed = models.BooleanField(default = False) The template is just the generic {{ form.player_1 }} with some jquery to hide/show player 2,3,4 depending on the select box value for number of players. Before I started adding jquery code to the template, this worked fine. Any ideas what could have happened?! Thanks in advance! Brendan -- 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/739d4756-c09b-45df-9173-627db8ebc839%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Multiple Model Form Generation
> > Why not just do this? (Sorry for the crappy indentation.. tab doesn't work > on here for some reason) > > models.py: > > >> class SignUpForm(forms.ModelForm): >> class Meta: >> model = Customer >> > > class VmForm(forms.ModelForm): > class Meta: > model = Vms > > class VmSpecForm(forms.ModelForm): > class Meta: > model = Vmspecs > > views.py > > def index(request): > if request.POST: > form = SignUpForm1(request.POST or None) > formb = VmForm(request.POST or None) > formc = VmSpecForm(request.POST or None) > > if form.is_valid() and formb.is_valid() and formc.is_valid() > form.save() > formb.save() > formc.save() > else > > load template and forms etc.. > -- 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/419a1b4b-72df-4595-9c4c-13d8f265878c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Multiple Model Form Generation
Why not just do this? (Not sure if this is the most efficient way..) models.py: > class SignUpForm(forms.ModelForm): > class Meta: > model = Customer > class VmForm(forms.ModelForm): class Meta: model = Vms class VmSpecForm(forms.ModelForm): class Meta: model = Vmspecs views.py def index(request): form = SignUpForm1(request.POST or None) formb = VmForm(request.POST or None) formc = VmSpecForm(request.POST or None) if form.is_valid() and formb.is_valid() and formc.is_valid() form.save() formb.save() formc.save() else load template and forms etc.. -- 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/d8bcc714-3e4d-4867-a442-5cced9a4ea96%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django Database Data Type
Thanks a lot for the reply! It got me thinking and I changed the code around a bit and was able to get the result I was looking for. What I did in the end was: teecolor = GolfCourseTees.objects.filter(Course_Name='course').values() tee1 = teecolor[0] and in the HTML i used {{ tee1.hole1_distance }} etc.. which got me the correct value. I had tried this before but left out .values() due to lack of understanding at the time. Thanks! Brendan -- 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/ce119395-0880-4a2e-bb9c-185d0dcf3952%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django Database Data Type
Hi, I have just started learning Django (been flip flopping between meteor and django, cant decide which to use..) and I am fairly new to web development in general. Basically, I have a query where I am using the code "teecolor = GolfCourseTees.objects.values('Tee_Color').filter(Course_Name=course)" but I want to take the value retrieved form this and use it to make another query before loading the template. When I set color1= teecolor[0] color 1 will show as: {'Tee_Color': u'Blue'}, and I am unsure why this happens. I want to retrieve only the value "blue" in this case. The reason for this is each course has usualy 4-5 tee colors. therefore I will have color1 = teecolor[0], color 2 = teecolor[1] etc.. so that I can insert that into a second query. Questions: 1) What is the data output "{'Tee_Color': u'Blue'}" called and why does it display like this (I would like to understand and not just insert a given line of code)? I have read the documentation and I am still confused on this. 2) How can I retrieve blue from {'Tee_Color': u'Blue'}? (example code would be helpful) Brendan -- 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/a10e6d29-9fc9-483a-958f-f62385e7301b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django Query Data
Hi, I have just started learning Django (been flip flopping between meteor and django, cant decide which to use..) and I am fairly new to web development in general. Basically, I have a query where I am using the code "teecolor = GolfCourseTees.objects.values('Tee_Color').filter(Course_Name=course)" but I want to take the value retrieved form this and use it to make another query before loading the template. When I set color1= teecolor[0] color 1 will show as: {'Tee_Color': u'Blue'}, and I am unsure why this happens. I want to retrieve only the value "blue" in this case. The reason for this is each course has usualy 4-5 tee colors. therefore I will have color1 = teecolor[0], color 2 = teecolor[1] etc.. so that I can insert that into a second query. To do that these values need to be "blue" "black" etc Questions: 1) What is the data "{'Tee_Color': u'Blue'}" output "{'Tee_Color': u'Blue'}" called and why does it display like this (I would like to understand and not just insert a given line of code)? I have read the documentation and I am still confused on this. 2) How can I retrieve blue from {'Tee_Color': u'Blue'}? (example code would be helpful) Brendan -- 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/2d92f660-db45-4c23-9525-f6f42fac5bca%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.