我想让在我网站上注册的用户提交"项目列表"通过django形式。我正在使用django-allauth。提交此表单后,我希望数据在唯一的URL上呈现,可以由公众浏览。
我的模板:
<form class="listing" id="listing_form" method="post" action="">
{{ form.as_p }}
<input type="hidden" name="{{ redirect_field_name }}" value="/" />
<button type="submit">Submit</button>
</form>
我的表格:
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from account.models import EmailAddress
from account.conf import settings
from projectListing.models import ProjectListing
class ProjectListingForm(ModelForm):
class Meta:
model = ProjectListing
fields = ('company', 'title', 'short_description', 'full_description', 'skills_required', 'hours_per_week', 'number_of_weeks', 'start_date', 'end_date', 'location')
我的模特:
from __future__ import unicode_literals
from django.conf import settings
from django.db import models
from employerProfiles import models as employerModels
class ProjectListing(models.Model):
company = models.ForeignKey(employerModels.EmployerProfile)
title = models.CharField(max_length = 200)
short_description = models.CharField(max_length = 200)
full_description = models.TextField()
skills_required = models.TextField()
photo = models.ImageField(upload_to='uploads/listingPhotos')
hours_per_week = models.DecimalField(max_digits=4, decimal_places=2)
number_of_weeks = models.IntegerField()
start_date = models.DateField(auto_now=False, auto_now_add=False)
end_date = models.DateField(auto_now=False, auto_now_add=False)
location = models.CharField(max_length=100)
def __unicode__(self):
return self.company
最好的方法是什么?谢谢!