django-forms

Django inline formset error

穿精又带淫゛_ 提交于 2019-12-24 17:48:40
问题 I'm trying to add an inline formset to a form. Here's the minimal code for reproducing the error: models.py class Festival(Model): desc = TextField(max_length=1000) class FestivalAddress(Model): festival = ForeignKey(Festival, related_name="addresses") name = CharField(max_length="50") urls.py urlpatterns = patterns('', url('^add/$', FestivalCreateView.as_view(), name='festival_add'), ) views.py class FestivalCreateView(CreateView): model = Festival form_class = FestivalForm #Add

NOT NULL constraint failed: accounts_myuser.password

♀尐吖头ヾ 提交于 2019-12-24 17:44:24
问题 I am doing a web application in django where users can create accounts. I'm storing the users' passwords in plaintext as authentication in my system does not totally depend on password but also on the otp. The problem I'm facing all of a sudden(it worked fine earlier) at the POST request of registration, is "NOT NULL constraint failed: accounts_myuser.password". I tried deleting database and migrations and re-migrated but it didn't help. I'm giving the ModelForm and the Model(custom one)

how to include class based views in context_processors in django?

别来无恙 提交于 2019-12-24 16:08:47
问题 I have this code in context_processors.py class ContactFormView(FormView): form_class = ContactForm template_name = "blog/contact.html" success_url = "/contact/" def form_valid(self,form): contact_name = form.cleaned_data.get('contact_name') contact_email = form.cleaned_data.get('contact_email') form_content = form.cleaned_data.get('content','') try: send_mail(contact_name,form_content,contact_email,[settings.EMAIL_HOST_USER], fail_silently=False) except BadHeaderError: return HttpResponse(

Only last label input value being returned in Django

馋奶兔 提交于 2019-12-24 15:51:57
问题 I am pretty new in Django and I guess there is something I am overlooking. I have a form that I am populating dynamically as shown below <form method="post"> {% csrf_token %} {{ profile.days }}//Only prints last radio button value {% for period, value in profile.periods.items %} <h2>{{ period }} Reports</h2> <label> <input name="days" value={{ value }} type="hidden"> <input name="reports_allowed" type="radio" {% if profile.reports_allowed and profile.days == value %} checked {% endif %}> Each

Django. Simple FormView not saving

本小妞迷上赌 提交于 2019-12-24 15:18:58
问题 I'm kind of new to django generic FormView. I'm missing something obvious, the form renders correctly but it is not saving the data: forms.py from perfiles.models import Perfil class FormEditarPerfil(forms.ModelForm): class Meta: model = Perfil fields = ('descripcion',) views.py from django.views.generic.edit import FormView from forms import FormEditarPerfil class EditarPerfil(FormView): template_name = "perfiles/editar_perfil.html" form_class = FormEditarPerfil def get_success_url(self):

Replacing ManyToMany-Relation with ModelChoiceField

别来无恙 提交于 2019-12-24 14:24:00
问题 I'm stuck trying to render a ManyToMany-Relation as a ModelChoiceField instead of a ModelMultipleChoiceField. So I tried the following (simplified): models.py: class Project(models.Model): name = models.CharField(max_length=20, unique=True) manager = models.ManyToManyField(User, related_name="manager_related") forms.py: class ProjectForm(forms.ModelForm): manager = forms.ModelChoiceField(queryset=User.objects.all(), empty_label='Choose Manager', required=False) class Meta: model = Project

FormWizard: How to proceed from step 1 to Step 2 when having own 2 templates

 ̄綄美尐妖づ 提交于 2019-12-24 14:12:21
问题 I have 2 steps in formwizard. the first step is where the customer filled up their particular and the second step is about building particular. models.py class customer(models.Model): LAST_NAME = models.CharField(max_length = 50) FIRST_NAME = models.CharField(max_length = 50) ADDRESS = models.CharField(max_length = 60, blank =True) def __unicode__(self): return '{0}' % (self) class building(models.Model): CUSTOMER = models.ForeignKey(customer, null = True, blank = True) BUILDING_USE = models

Django Error: __init__() got multiple values for keyword argument 'max_length'

╄→尐↘猪︶ㄣ 提交于 2019-12-24 13:57:08
问题 I am getting this error. I do not understand the head and tail of it. __init__() got multiple values for keyword argument 'max_length' . I am adding three fields to UserCreationForm from django.contrib.auth.forms , which are email , first name and last name and I want to save them to my User object. (Does the first name and last name gets saved automatically). Here is my form that I am trying to load. class MyRegistrationForm(UserCreationForm): #define fields email=forms.EmailField(required

How to use admin.TabularInline in a ModelForm

非 Y 不嫁゛ 提交于 2019-12-24 13:54:50
问题 full story Only validate admin form if condition is true I am trying to validate that a form has an answer. In order to validate a form in the admin you need to make a new form and tell the admin.ModelAdmin class to use that form. Is this correct? I have created a form but now I can't use my inlines form. If I put it in the admin.ModelAdmin it still shows up and I can still fill that part out but it doesn't appear in the form cleaned_data if though it is in the post data. How do I use

Accessing shared smb ubuntu in python scripts

≯℡__Kan透↙ 提交于 2019-12-24 13:41:09
问题 I have a shared ubuntu drive on my network that I can access in nautilus using smb://servername/sharedfolder or smb:///sharedfolder. I need to be able to access it python scripting from my ubuntu machine (8.10), but I can't figure out how. I tried the obvious way (same address as nautilus), but wasn't successful. To play around, I tried printing the content of that folder with both: Code: for file in os.listdir("smb://servername/sharedfolder") print file Both give me "no file or directory"