django-forms

save multiple uploaded files in django

我与影子孤独终老i 提交于 2019-12-22 04:36:25
问题 I want to upload and save multiple files in my application, I have <input type="text" name="name" value="" /> <input type="file" name="file" multiple/> in my template. when I hit upload, seems form = MyForm(request.POST, request.FILES) is only saving one file which is last in the list of the many uloaded files. How can I be able to save all the uploaded files using the form form = MyForm(request.POST, request.FILES) blah blah ? Thanks Edit Myform is a model form from this model. class Docs

Django error: “'ChoiceField' object has no attribute 'is_hidden'”

隐身守侯 提交于 2019-12-22 04:29:08
问题 Django template throws 'AttributeError' when rendering..What I want to achive is that in the template the resolted forn will contain a select box with the values from the list below. Here's the Forms.py file: class CallForm (forms.ModelForm): class Meta(): model = Call widgets = { 'employee_id' : forms.ChoiceField(choices=FormsTools.EmployeesToTuples(Employee.objects.all())) } Explanation: FormsTools.EmployeesToTuples(Employee.objects.all()) --> [(1, u'E1'), (2, u'E2'), (3, u'E3')] Here is

Django admin: how to format readonly fields?

假装没事ソ 提交于 2019-12-22 04:15:31
问题 I have a model, Director with two DateFields, and two subclasses (code below). I am trying to create an admin page for each Director which shows the corresponding subclass instance, and not the Director instance; this part is mostly easy (I create an inline for each subclass, give the main ModelAdmin a form with all fields excluded, and have the main ModelAdmin only request formsets from the inlines which have a corresponding instance - the code; there is an unresolved issue with this

How to append error message to form.non_field_errors in django?

♀尐吖头ヾ 提交于 2019-12-22 04:01:20
问题 I have a form with several fields. I have separate validation checks for each field, done via the forms validation. I however also need to check if few fields are filled in before redirecting the user to a different view. I was hoping I could somehow append the error to forms.non_field_errors as it is not for a particular field , but I am not sure what the right syntax for this would be. I have checked online and found.. form.errors['__all__'] = form.error_class(["error msg"]) This displays

Autocomplete field in Django

有些话、适合烂在心里 提交于 2019-12-22 03:51:08
问题 I have models similar to the following: class Country(models.Model): name = models.CharField(max_length=50, unique=True) class City(models.Model): name = models.CharField(max_length=50, unique=True) country = models.ForeignKey(Country) and essentially I want to add a City to the database in my template. Before that, i should link it to the Country that already exists, so i want to use 'autocomplete field' in my template to get Country from DB I have the following form defined: class

Change clickable field in Django admin list_display

亡梦爱人 提交于 2019-12-22 01:27:01
问题 In Django 1.8.6, by default, whenever I provide a list_display option to a ModelAdmin subclass, the first field in the list becomes clickable and leads to the object edit page. Is there a way to keep the order of the fields in list_display , but change the clickable one? Currently, I have the id field clickable (it goes first in list_display ), which is a tad small. I would like to better click on, say, name to go to the edit page. 回答1: You could have a look at django.contrib.admin.ModelAdmin

Error adding more fields with django-autocomplete-light

纵饮孤独 提交于 2019-12-22 00:12:22
问题 I have a problem and I am using 2 libraries : django-autocomplete-light and django-dynamic-formset . The 2 are very good at doing their job. The first is used to do autocomplete and the second to make django formsets are dynamic. but when you want to join these 2 a problem occurs. Image of the problem when a new field is created, it is added in that way. Template: {% extends 'base/base.html' %} {% load static %} {% block titulo%} Registrar venta {%endblock%} {% block contenido %} <div class=

Django Formsets - form.is_valid() is False preventing formset validation

只谈情不闲聊 提交于 2019-12-21 23:19:58
问题 I'm am utilizing a formset to enable users subscribe to multiple feeds. I require a) Users chose a subscription by selecting a boolean field, and are also required to tag the subscription and b) a user must subscribe to an specified number of subscriptions. Currently the below code is capable of a) ensuring the users tags a subscription, however some of my forms is_valid() are False and thus preventing my validation of the full formset. [edit] Also, the relevant formset error message fails to

Setting initial value of Django ModelChoiceField

◇◆丶佛笑我妖孽 提交于 2019-12-21 22:27:57
问题 I have an Model with an m2m-Fields to an OtherModel. class OtherModel(models.Model) name = models.CharField(max_length=100, null=True) class Model(models.Model) name = models.CharField(max_length=100, null=True) otherModel = models.ManyToManyField(OtherModel) For the class Model I use an normal FormSet(). For the class otherModel I use a formset_factory() I only want to allowed to select data from the database from OtherModel so I changed the CharField name in OtherModel to a ModelChoiceField

Django: Creating a unique identifier for a user based on request.META values

懵懂的女人 提交于 2019-12-21 21:35:00
问题 I'm looking at creating an anonymous poll. However, I want to prevent users from voting twice. I was thinking of hashing some request.META values like so: from hashlib import md5 request_id_keys = ( 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT', 'HTTP_ACCEPT_ENCODING', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_CONNECTION', 'HTTP_USER_AGENT', 'REMOTE_ADDR', ) request_id = md5('|'.join([request.META.get(k, '') for k in requst_id_keys])).hexdigest() My questions: Good idea? Bad idea? Why? Are some of these keys