django-forms

Django Edit Profile - 'bool' object is not callable

非 Y 不嫁゛ 提交于 2021-02-10 18:31:44
问题 So I just followed this tutorial to create a profile for a user and allow them to edit it but I get this error when I go and visit the edit page 'bool' object is not callable File "C:\Users\...\account\userprofile\views.py", line 64, in profile_edit_view if request.user.is_authenticated() and request.user.id == user.id: TypeError: 'bool' object is not callable models.py: from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save

django forms post request raising an error on __init__ method

怎甘沉沦 提交于 2021-02-10 15:57:16
问题 I have a django form which takes a paramater from the view to initialize the MultipleChoiceField based on the user instance. The form is working fine when loading the template. when i submit the form the init method in the form raising an error. My Model models.py from django.db import models from django.contrib.auth.models import User class Group(models.Model): group_name = models.CharField('Group name', max_length=50) def __str__(self): return self.group_name class GroupMembers(models.Model

django forms post request raising an error on __init__ method

假如想象 提交于 2021-02-10 15:55:00
问题 I have a django form which takes a paramater from the view to initialize the MultipleChoiceField based on the user instance. The form is working fine when loading the template. when i submit the form the init method in the form raising an error. My Model models.py from django.db import models from django.contrib.auth.models import User class Group(models.Model): group_name = models.CharField('Group name', max_length=50) def __str__(self): return self.group_name class GroupMembers(models.Model

MultiValueField does not work with ModelChoiceField

我的梦境 提交于 2021-02-10 15:49:20
问题 The code: (where AddressInput is a MultiWidget) class AddressInput(widgets.MultiWidget): def __init__(self, attrs=None): self.widgets = widgets.HiddenInput(attrs), widgets.TextInput(attrs) # note that the second widget would be customized, I'm only providing simplified example, which does produce the same error super().__init__(self.widgets, attrs) def decompress(self, value): try: address = AddressPoint.objects.get(pk=value) except (AddressPoint.DoesNotExist, ValueError): address = None

How to handle data from two forms in one view?

ε祈祈猫儿з 提交于 2021-02-10 15:46:26
问题 So I have two forms.ModelForm for my two models First: class TranslatorChoice(forms.ModelForm): def __init__(self, *args, **kwargs): self.user_id = kwargs.pop('user_id',None) super(TranslatorChoice, self).__init__(*args, **kwargs) self.fields['owner'].queryset = Translator.objects.all().filter(owner_id = self.user_id) owner = forms.ModelChoiceField(queryset = None) class Meta: model = Translator fields = ('owner',) Second: class ProfileChoice(forms.ModelForm): def __init__(self, *args, *

Django duplicate key when trying to send a form with foreign key

为君一笑 提交于 2021-02-10 14:35:09
问题 I need to save a form with listaflor and multiple instances of flora2estado,When i try to send this form i get: IntegrityError at /enviar_flora/ (1062, "Duplicate entry '99-10031' for key 'PRIMARY'") views.py: def CreateFlo(request): form = FloForm() if request.method == 'POST': form = FloForm(request.POST) if form.is_valid(): listafor = form.save() estados = form.cleaned_data.get('estados') for estado in estados: Flora2Estado.objects.create(especie=listafor, estado= estado) # or you can use

Django duplicate key when trying to send a form with foreign key

ⅰ亾dé卋堺 提交于 2021-02-10 14:34:12
问题 I need to save a form with listaflor and multiple instances of flora2estado,When i try to send this form i get: IntegrityError at /enviar_flora/ (1062, "Duplicate entry '99-10031' for key 'PRIMARY'") views.py: def CreateFlo(request): form = FloForm() if request.method == 'POST': form = FloForm(request.POST) if form.is_valid(): listafor = form.save() estados = form.cleaned_data.get('estados') for estado in estados: Flora2Estado.objects.create(especie=listafor, estado= estado) # or you can use

Where/how to replace default upload handler in Django CBV?

谁都会走 提交于 2021-02-10 05:53:07
问题 I am trying to specify a specific method of handling file uploads for a class based view. Per the docs this can be achieved by something like: from django.core.files.uploadhandler import TemporaryFileUploadHandler request.upload_handlers = [TemporaryFileUploadHandler(request=request)] If i specify this in post method of a FormView like so: def post(self, request, *args, **kwargs): request.upload_handlers = [TemporaryFileUploadHandler(request=request)] return super().post(self, request, *args,

Django extending user with userprofile (error: User has no profile.)

本秂侑毒 提交于 2021-02-10 05:11:52
问题 someone can told me, why this code don't working? I'm trying to create a registration form for users. I'm getting an error "RelatedObjectDoesNotExist at /signup/client/2/ User has no profile." views.py if request.POST: user_form = UserCreationForm(request.POST) profile_form = ProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.profile.city="WW" user.profile.phone="32323" user.profile.save() forms.py class UserForm(forms.ModelForm): class

Django extending user with userprofile (error: User has no profile.)

巧了我就是萌 提交于 2021-02-10 05:10:47
问题 someone can told me, why this code don't working? I'm trying to create a registration form for users. I'm getting an error "RelatedObjectDoesNotExist at /signup/client/2/ User has no profile." views.py if request.POST: user_form = UserCreationForm(request.POST) profile_form = ProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.profile.city="WW" user.profile.phone="32323" user.profile.save() forms.py class UserForm(forms.ModelForm): class