django-forms

error 'NoneType' object has no attribute '__dict__'

╄→尐↘猪︶ㄣ 提交于 2019-12-24 10:44:35
问题 I have encoutered this error and its not letting me save the info in the form. The initial data is showing well in the form but saving is challenging me. Hope someone can help, I'm really stuck class UserPostCreatView(CreateView): form_class = PostModelForm template_name = 'posts/post_form.html' success_url = "/profile/{user_slug}/wall" def get_initial(self): # Get the initial dictionary from the superclass method initial = super(UserPostCreatView, self).get_initial() user_slug = self.kwargs

need pointer on GeoPtProperty in app-engine/django forms

帅比萌擦擦* 提交于 2019-12-24 10:27:10
问题 I'm not looking for a bug fix so much as an approach. I'm a newbie with a simple model: classLocation(db.Model): name = db.StringProperty() geoPt = db.GeoPtProperty() ... I use that to make a simple form: class LocationForm(djangoforms.ModelForm): class Meta: model = Location When it renders out, the GeoPt is a single text field. For this form I'd prefer latitude and longitude fields, with validation. Which way to go? Is this a common problem with "complex objects" in django forms? If so, is

Displaying a specific field in a django form

 ̄綄美尐妖づ 提交于 2019-12-24 10:21:51
问题 I have the following field in a django form: position = forms.ModelChoiceField(Position.objects.order_by('-ordering'), empty_label='Select Position',) In my Position model, I am using the unicode field to display the field called "position". However, in this particular form, I want the output to be a different field in the model called "position-select". How would I do this without altering the default output of the unicode field? Thank you. 回答1: Try "subclassing ModelChoiceField and override

Whats the most Django/pythonic way to create or overwrite a record?

99封情书 提交于 2019-12-24 09:58:58
问题 Working with Django 1.2 I am making a wine review site. A user should only be able to review each wine once, but should be able to go back and re-review a wine without raising an error. Using the get_or_create method seems the most rational solution but I have been running into various problems implementing it. Searching I found this article which looked promising: Correct way to use get_or_create? and of course the django documentation on it: http://docs.djangoproject.com/en/1.2/ref/models

Django: AttributeError - Object has no attribute

安稳与你 提交于 2019-12-24 09:24:18
问题 This view is throwing the AttributeError saying :'PhotoForm' object has no attribute 'reservation'. What happens- the function passes, but doesn't actually upload the image. In debugging it, the form is not valid. I tried printing form.reservation form.message form.photo But that shows this traceback ( which is the reason why the form isn't valid & not completing the function. As I built this off other functions that are working, I'm a bit confused. Thanks for the help! The HTML Form <form

Django forms: need more than 1 value to unpack

扶醉桌前 提交于 2019-12-24 08:48:15
问题 I'm a newer to Python, and I am having a problem with Django's forms: args="[('job_201404181748_1712666','job_201404181748_1712666')]" jobid = forms.ChoiceField(choices=args) This raised ValueError: need more than 1 value to unpack . If I replace args with a string, then it works ok: jobid = forms.ChoiceField(choices=[('job_201404181748_1712666','job_201404181748_1712666')]) I don't know why. Can anyone help? 回答1: Try args without the surrounding quotes. By surrounding it with quotes, you

Django inlineformset_factory doesn't delete records

*爱你&永不变心* 提交于 2019-12-24 08:12:52
问题 Here is my code: PartFormSet = inlineformset_factory(ReservationPaper, ReservationPaperPart, ReservationPaperPartEditForm, extra=0) if request.method == "POST": try: part_formset = PartFormSet(data=request.POST, instance=rp) except: return HttpResponseRedirect(request.path_info) rp_form = ReservationPaperForm(instance=rp, data=request.POST) if part_formset.is_valid() and rp_form.is_valid(): rp_form.save() for part_form in part_formset.forms: part_form.save() return HttpResponseRedirect

Django views and forms submit button update database

我怕爱的太早我们不能终老 提交于 2019-12-24 07:38:20
问题 This is the form that the submit button is in. <form> <button type="submit" name="subscribe" class="btn btn-primary pull-right">Subscribe</button></h5> </form> And I have this code in my view: def tour_sub(request): tour = Tour.objects.filter(id=1) if 'subscribe' in request.POST: tour.subscribers.add(user) tour.save() When the subscribe button is clicked I just want to update the record and insert that in the database. But nothing happens when I click the Subscribe button. I am new in django

Django: ModelForms: ImageField is always empty and rejected by ModelForm

泄露秘密 提交于 2019-12-24 07:19:50
问题 I created a form based on several ModelForm elements. All fields work fine excluding the ImageField . Due to the missing ImageField form.is_valid() always returns False - even though I pass request.FILES to form. Why the form with the ImageField is always invalid / empty? Forms class UserProfileForm2(forms.ModelForm): class Meta: model = models.UserProfile fields = ['description', 'picture'] class LocationForm(forms.ModelForm): class Meta: model = models.Location fields = ['city', 'state',

same row multiple times in a form in django

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:19:22
问题 have a form by which user can enter details about some expenses but i want to have same row in the form again and again but couldn't find out how to do that : if you see figure above this forms works well for 1 row of data , saves well but with more then 1 row it cant . Can someone suggest any way to do that . Below are the codes : models.py from django.db import models class Expenditure(models.Model): exp_date = models.DateField("Expenditure_Date") description = models.CharField(max_length