django-forms

django - what goes into the form action parameter when view requires a parameter?

前提是你 提交于 2019-12-18 11:02:31
问题 This is what I have: myview.py with a view that takes a parameter user : def myview(request, user): form = MyForm(request.POST) .... return render_to_response('template.html',locals(), context_instance=RequestContext(request)) The user gets passed through an url. urls.py : ... urlpatterns += patterns('myview.views', (r'^(?P<user>\w+)/', 'myview'), ) ... I also have a template.html with a form: <form name="form" method="post" action="."> ... </form> What goes in the the form action parameter

django - what goes into the form action parameter when view requires a parameter?

只谈情不闲聊 提交于 2019-12-18 11:02:23
问题 This is what I have: myview.py with a view that takes a parameter user : def myview(request, user): form = MyForm(request.POST) .... return render_to_response('template.html',locals(), context_instance=RequestContext(request)) The user gets passed through an url. urls.py : ... urlpatterns += patterns('myview.views', (r'^(?P<user>\w+)/', 'myview'), ) ... I also have a template.html with a form: <form name="form" method="post" action="."> ... </form> What goes in the the form action parameter

creating django forms

断了今生、忘了曾经 提交于 2019-12-18 10:26:20
问题 I'm struggling to get my head round django forms.. I've been reading various documentation but just can't quite grasp the concepts. I have got to grips with models, views and templates. What I am trying to do is to create a form with various fields composing of dropdown lists and checkboxes which are populated by values in a database. I have a working app called vms. Using the models.py I have a built a simple schema that holds size and type. Size consists of 'small', 'medium' & 'large'. Type

Pseudo-form in Django admin that generates a json object on save

半腔热情 提交于 2019-12-18 10:25:15
问题 I have a model with a field for a json object. This object is used on the site to control some css variables, among other things. Right now in the admin, I have a text field where a user can save a json object. I'd like to show a form with all the attributes that, upon saving, will generate a json object. Basically, the user sees, and the data is stored, like this: { "name":"hookedonwinter", "user-id":123, "basics":{ "height":150, "weight":150 } } And I'd rather have the user see this: Name:

Django's forms.Form vs forms.ModelForm

我们两清 提交于 2019-12-18 10:00:28
问题 Could anyone explain to me similarities and differences of Django's forms.Form & forms.ModelForm ? 回答1: Forms created from forms.Form are manually configured by you. You're better off using these for forms that do not directly interact with models. For example a contact form, or a newsletter subscription form, where you might not necessarily be interacting with the database. Where as a form created from forms.ModelForm will be automatically created and then can later be tweaked by you. The

How to restrict my students to don't access teacher area in django? [closed]

两盒软妹~` 提交于 2019-12-18 09:52:25
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . I'm creating a website where there is two types of users, Students and Teachers. I had created one register and login page for authentication. Now by default all the users who sign up will be the students and can access the videos and also accessing teachers area (I did the

How to restrict my students to don't access teacher area in django? [closed]

泪湿孤枕 提交于 2019-12-18 09:52:17
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . I'm creating a website where there is two types of users, Students and Teachers. I had created one register and login page for authentication. Now by default all the users who sign up will be the students and can access the videos and also accessing teachers area (I did the

Need to have a Required and Optional Fields in Django Formset

耗尽温柔 提交于 2019-12-18 09:39:50
问题 I created a formset that has maximum of 5 images to be attached; 1 - but I want the Validation to run only when the user has not attached any image (ValidationError('atleast 1 image is required')) , 2- This program is also not allowing the User to save when 1, or 2, or 3 images are attached, which I really need. So if there is 1 image or 2, that should be allowed to save. 3 - I also need to make the 1 radio-button to be selected by default, to make the selected image to be the one dispalyed

Django: how to exclude the bogus option '----' from select element generated from modal form field?

て烟熏妆下的殇ゞ 提交于 2019-12-18 09:27:50
问题 models.py: class Foo(models.Model): ... TIME_UNIT_TYPE = ( ('D', 'Day'), ('W', 'Week'), ('M', 'Month'), ) time_unit = models.CharField(max_length=1, choices=TIME_UNIT_TYPE) ... forms.py: class FooForm(ModelForm): class Meta: model = Foo fields = (time_unit,) When time_unit is rendered in the template, the resultant select element contains a bogus '----' option that I don't need for my app. I can remove this bogus option inside init () or redefine the time_unit attribute inside the FooForm.

disabled field is not passed through - workaround needed

帅比萌擦擦* 提交于 2019-12-18 05:44:21
问题 I have a form with which I want to update a MyModel object. On the model there is a unique_together constraint, fieldA together with fieldB. In the form in the clean method I check for this unique constraint. For some reasons I have to show fieldA as readonly in the update. Thus fieldA is not passed through. My issue is that if the form does not validate, the form is re-shown, but I have lost the value in fieldA. I tried to reset the cleaned_data['fieldA'], but it does not work. Any idea what