django-forms

Django form upload request.files empty

笑着哭i 提交于 2021-02-18 12:18:05
问题 I havent posted a question here before, read mostly. Im learning Django and got file upload working before . But now i've broke it somehow. request.FILES is empty when im uploading but i can see the filename in request.raw_post_data. here is the code for the html <form enctype="multipart/form-data" method="post" action="">{% csrf_token %} {{ form.as_p }} <input type="submit" name="submit" value="Upload Photo" /> </form the form class PhotoUploadForm(forms.Form): title = forms.CharField(max

Django modelformset_factory delete modelforms marked for deletion

你离开我真会死。 提交于 2021-02-18 11:21:22
问题 When using modelformset_factory how do you delete objects from the database that get marked for delete in the form? I create my modelformset_factory like this: ItemFormset = modelformset_factory(Item, ItemModelForm, extra=1, can_delete=True) qset = Item.objects.filter(pr=pr) formset = ItemFormset(queryset=qset) When the formset comes back in the POST I get the data like so: if request.method == "POST": formset = ItemFormset(request.POST,queryset=qset) if formset.is_valid(): marked_for_delete

Auto Populate Slug field django

久未见 提交于 2021-02-18 11:10:14
问题 I have a model defined and over 100+ entries of data in my DB. I would like to auto populate a slug field and see it show up in the admin, since adding new entries for 100+ fields is not something I would like to do. AutoSlug() field doesnt seem to be working when I add it to my model and make the migrations, prepopulated_fields = {'slug': ('brand_name',)} does not work using it within my admin.py and as well I have tried to add the default field on the slug as my desired field name within

Auto Populate Slug field django

删除回忆录丶 提交于 2021-02-18 11:05:39
问题 I have a model defined and over 100+ entries of data in my DB. I would like to auto populate a slug field and see it show up in the admin, since adding new entries for 100+ fields is not something I would like to do. AutoSlug() field doesnt seem to be working when I add it to my model and make the migrations, prepopulated_fields = {'slug': ('brand_name',)} does not work using it within my admin.py and as well I have tried to add the default field on the slug as my desired field name within

Auto Populate Slug field django

感情迁移 提交于 2021-02-18 11:03:59
问题 I have a model defined and over 100+ entries of data in my DB. I would like to auto populate a slug field and see it show up in the admin, since adding new entries for 100+ fields is not something I would like to do. AutoSlug() field doesnt seem to be working when I add it to my model and make the migrations, prepopulated_fields = {'slug': ('brand_name',)} does not work using it within my admin.py and as well I have tried to add the default field on the slug as my desired field name within

django How to execute a function asynchronously i.e, handover a task to a sub process and return response

天大地大妈咪最大 提交于 2021-02-13 05:37:50
问题 I am using django 2.0 and python 3.6. The user registration includes sending of a verification mail. And this mail sending process is taking longer and the user is kept waiting. What I need?: If the user registration form is valid, mailing details are sent to another task handler and regardless of whether the mail is sent or not, the function must resume and return a response. def new_user_registration(request): form = CustomUserCreationForm(request.POST or None) if form.is_valid(): user =

How do I change the 'name' HTML attribute of a Django Form field?

风格不统一 提交于 2021-02-11 17:35:42
问题 I have a Django 3.0 form # forms.py class SignupForm(UserCreationForm): email = forms.EmailField() This renders as the HTML element <input type="text" name="email" required id="id_email"> Is there a way to change the 'name' attribute? The widgets documentation suggests that either of these might work: # forms.py class SignupForm(UserCreationForm): email = forms.EmailField( widget = forms.TextInput( attrs = {'name': 'email_address'} ) ) or # forms.py class SignupForm(UserCreationForm): email =

Django 'ManagementForm data is missing or has been tampered with' foreign manytomany foreign key

妖精的绣舞 提交于 2021-02-11 12:50:35
问题 I'm getting this error after submitting my form(it uses inlines and foreign keys). This is a follow up to my question: How to save a model in ModelForm with two ForeignKey fields in Django Now my views.py looks like this: def CreateFlo(request): EstadosInlineFormSet = inlineformset_factory(Listaflor, Flora2Estado, form=Flo2Form) floForm = FloForm(request.POST) if request.method == 'POST': if floForm.is_valid(): new_flo = floForm.save() estadosInlineFormSet = EstadosInlineFormSet(request.POST,

Django DateField format impossible to validate and save to model

让人想犯罪 __ 提交于 2021-02-11 12:26:26
问题 Old issue, I know. But I still could not find a working solution so I may have missed something obvious. Here is my form class AddPatientForm(forms.Form): last_name = forms.CharField(label='Nom', max_length=40) first_name = forms.CharField(label='Prénom', max_length=40) birthday = forms.DateField(label='date de naissance', widget=forms.DateInput(format='%d/%m/%Y',attrs={'placeholder': '31/03/1989'}), input_formats=['%d/%m/%Y',]) It follows this format convention and has to do so . Here is my

AttributeError on successful redirection in django?

谁说我不能喝 提交于 2021-02-11 06:42:37
问题 Redirection on successful POST request from Host View. def product_page_view(request, prod_slug, color=None, size=None): ... ... prod = Product.objects.filter(slug=prod_slug).first() seller = prod.seller ... .... order_form = Buy_now_form() if request.method == "POST": order_form = Buy_now_form(request.POST) if order_form.is_valid(): # Function for processing POST request and return order order = buy_now_view(request, prod.slug, color, size) # Redirection return redirect(reverse('product