django-forms

Dynamic forms in django-admin

我怕爱的太早我们不能终老 提交于 2020-01-12 02:31:33
问题 I want to make admin add-form dynamic. I want to add few formfields depending on setting in related object. I have something like this: class ClassifiedsAdminForm(forms.ModelForm): def __init__(self,*args, **kwargs): super(ClassifiedsAdminForm, self).__init__(*args, **kwargs) self.fields['testujemy'] = forms.CharField(label = "test") And in admin.py: class ClassifiedAdmin(admin.ModelAdmin): def get_form(self, request, obj=None, **kwargs): return ClassifiedsAdminForm As you can see, I want to

Get the type of field in django template

别说谁变了你拦得住时间么 提交于 2020-01-11 18:50:44
问题 I am using django forms and I want to use Twitter Bootstrap's css in my html. so my template looks like this: {% for field in form %} <div class="form-group"> {{ field.label_tag }}<!--Same thing as : <label for="{{field.id_for_label}}"></label> --> <input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="Email"> </div> {% endfor %} I can't figure out out to get the type value. {{field.type}} . Is there any way to get the type of the input field in django templates

Get the type of field in django template

限于喜欢 提交于 2020-01-11 18:50:08
问题 I am using django forms and I want to use Twitter Bootstrap's css in my html. so my template looks like this: {% for field in form %} <div class="form-group"> {{ field.label_tag }}<!--Same thing as : <label for="{{field.id_for_label}}"></label> --> <input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="Email"> </div> {% endfor %} I can't figure out out to get the type value. {{field.type}} . Is there any way to get the type of the input field in django templates

Django: How to add an extra form to a formset after it has been constructed?

被刻印的时光 ゝ 提交于 2020-01-11 17:26:40
问题 This is roughly what I'm trying to do: def post(request): VehicleFormSet = formset_factory(StaffVehicleForm) if request.method == 'POST': vehicle_formset = VehicleFormSet(request.POST) if 'add_vehicle' in request.POST: if vehicle_formset.is_valid(): form_count = vehicle_formset.total_form_count() vehicle_formset.forms.append(vehicle_formset._construct_form(form_count)) Basically, if a user clicks the "Add" button and their entry is valid, I want to add another blank form to the formset, and

Variable number of inputs with Django forms possible?

廉价感情. 提交于 2020-01-11 15:46:35
问题 Is it possible to have a variable number of fields using django forms? The specific application is this: A user can upload as many pictures as they want on the image upload form. Once the pictures are uploaded they are taken to a page where they can give the pictures a name and description. The number of pictures will depend on how many the user has chosen to upload. So how do I get django to generate a form using a variable number of input fields (which could be passed as an argument if

Listing only usable values in OneToOneField Django

萝らか妹 提交于 2020-01-11 13:35:29
问题 I want to list only usable items in OneToOneField not all items, its not like filtering values in ChoiceField because we need to find out only values which can be used which is based on the principle that whether it has been used already or not. I am having a model definition as following: class Foo(models.Model): somefield = models.CharField(max_length=12) class Bar(models.Model): somefield = models.CharField(max_length=12) foo = models.OneToOneField(Foo) Now I am using a ModelForm to create

Can you change a field label in the Django Admin application?

拥有回忆 提交于 2020-01-10 11:51:27
问题 As the title suggests. I want to be able to change the label of a single field in the admin application. I'm aware of the Form.field attribute, but how do I get my Model or ModelAdmin to pass along that information? 回答1: the verbose name of the field is the (optional) first parameter at field construction. 回答2: If your field is a property (a method) then you should use short_description: class Person(models.Model): ... def address_report(self, instance): ... # short_description functions like

Can you change a field label in the Django Admin application?

痴心易碎 提交于 2020-01-10 11:48:51
问题 As the title suggests. I want to be able to change the label of a single field in the admin application. I'm aware of the Form.field attribute, but how do I get my Model or ModelAdmin to pass along that information? 回答1: the verbose name of the field is the (optional) first parameter at field construction. 回答2: If your field is a property (a method) then you should use short_description: class Person(models.Model): ... def address_report(self, instance): ... # short_description functions like

Saving Django ModelForm with a ForeignKey

二次信任 提交于 2020-01-10 10:41:07
问题 This is probably a fairly simple question, but I can't seem to figure it out from the Django Docs. I'm trying to save a two ModelForms at once with one being a ForeignKey of another. I'm not sure how to write the logic in the views to ensure these go together properly. models.py class Address(models.Model): address = models.CharField(max_length=100) city = models.CharField(max_length=50) zipcode = models.PositiveIntegerField() class Store(models.Model): name = models.CharField(max_length=100)

Reverse for 'update_comment' with arguments '('',)' not found. 1 pattern(s) tried: ['comment\\/(?P<news_pk>[0-9]+)$']

こ雲淡風輕ζ 提交于 2020-01-10 04:38:26
问题 I'm coding a news site.Now I'm detailing with the comment post function.And meet the issue says: Reverse for 'update_comment' with arguments '('',)' not found. 1 pattern(s) tried: ['comment\\/(?P<news_pk>[0-9]+)$'] I have tried many ways and times but still can't solve it and I can't find any wrong with my code.And really need your help. The comment post function is in the news_detail.html. There are two important apps in my project news and operation comment models is under operation Here is