Django Fields In Form
I am a beginner in Django, hence this might be a simple issue. But I'm not able to get past this successfully. This is my models.py class Category(models.Model): name = models
Solution 1:
I believe the issue with the dropdown is that you've excluded the fields from
ImageForm
. You have:fields = ('file','cost_price','set_cat_no','set_cat_name',)
but should have:
fields = ('file','cost_price','set_cat_no','set_cat_name', 'category', 'fabric', 'manufacturer
,)`if that doesn't work, are there any options in your database for
Categories
,Fabric
, andManufacturer
? If your tables are empty, the dropdown will be empty. If there are values in the database, is there HTML being generated but the label value is blank (i.e.<option>{this is blank}</option>
)? In django, you can override the__str__
function to specify how the dropdown options get labeled
Override __str__
as follows:
classCategory(models.Model):
name = models.CharField(max_length=128)
abbr = models.CharField(max_length=5)
def__unicode__(self):
returnself.name
def__str__(self):
returnself.name
- You can compute the value of
selling_price
and any other computed value in the blockif request.method == 'POST'
.
Example:
def uploadphoto(request):
context = RequestContext(request)
context_dict = {}
if request.method == 'POST':
form = ImagesForm(request.POST,request.FILES)
#- Calculate value(s) here -#
if form.is_valid():
image = form.save(commit=False)
image.save()`
- Please see this post here for using radio buttons
- You would do this in the same place as #2 above
Post a Comment for "Django Fields In Form"