django-forms

I need advice on how to implement a checkbox in Django

拟墨画扇 提交于 2019-12-14 02:32:22
问题 I am trying to create a way that a student can enroll to a teacher's course. I added a boolean field to my StudentData model and from there I added a many-to-many field to my Course model. Each of my course page is a generated slug page and there all students are listed. I want that near each student a checkbox will be shown. And if teacher selects more students and presses Enroll button, only those students can view the course. Now, the template conditionals I can do them myself, but I am

Django how to modify database records by template

一个人想着一个人 提交于 2019-12-14 02:15:34
问题 I want to delete the records which i select, and run.html will refresh, how can i do that? Since i use function run in views.py to send records in database, and run need one parameter build which can be got by using run.name , so i think i need to pass "run.name" and "run.id" when i click the submit button. urls.py urlpatterns = patterns('', (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^home/$', 'views.home'), (r'^home/(?P<build>[^/]+)/$'

Ajax succesfull call show div with form data

眉间皱痕 提交于 2019-12-14 00:24:19
问题 views.py def index(request): """""""""""""" registerform = UserRegisterForm(request.POST) createprofileform = UserCreateProfileForm(request.POST) if registerform.is_valid() and createprofileform.is_valid(): result = registerform.save(commit=False) result.set_password(request.POST['password']) #set member password result.username = username result.save() member.user_id = user.id member.member_id = result.id member.save() #new member registration member_profile = UserProfile.objects.get(user

form_valid method in django-extra-views. In reality form(s)_valid

独自空忆成欢 提交于 2019-12-13 20:28:23
问题 I am trying to use Django Extra Views pack to create new entry based on model + inline formset + extra information from the USER model. I know how to do it via function based views but now trying to decrease amount of the code: I have 2 models + user model: Model1: # primary model author = models.ForeignKey("ExtraUser", ) +some fileds Model2 # secondary model photo = models.ForeignKey("Model1", ) + some fields # user model Model ExtraUser(AbstractBaseUser) + some fileds I use following VIEW

Django Formset populating when it should be blank

余生长醉 提交于 2019-12-13 19:09:44
问题 My goal is to have a formset that lists 5 versions of the same form. On submit the form should create the filled out forms in the DB. My issue is that the forms come repopulated with data. Which is bad. Any thoughts on what I might be doing wrong? Models.py from django.db import models from django.contrib.auth.models import User PRIORITIES = ( ('1', 'High'), ('2', 'Medium'), ('3', 'Low'), ) class Todo(models.Model): task = models.CharField(max_length=200) owner = models.ForeignKey(User)

Can we give dynamic queryset for ModelChoiceField in django forms?

ぃ、小莉子 提交于 2019-12-13 16:25:46
问题 I want create a model form, which has a foreign key in the model. Like: class TestModel(Model): field1=ForeignKey(RefModel) I create a form like: class TestForm(ModelForm): class Meta(object): model = TestModel widgets = {'field1': RadioSelect} But I want to do some limitation on the field according to the url, which means it's not constant data, what should I do to change the queryset for field1 of TestForm? 回答1: You can override the field. use field1 = ModelChoiceField(queryset=<<your

Django: difference between is_valid and form_valid

混江龙づ霸主 提交于 2019-12-13 13:39:52
问题 I've created a form which is a forms.ModelForm . On the "view" side, I've created a view which is a generic.UpdateView . In those 2 differents classes, I have is_valid() on one side, and form_valid() on the other side. class ProfileForm(FormForceLocalizedDateFields): class Meta: model = Personne fields = ('sexe', 'statut', 'est_fumeur', 'est_physique', 'date_naissance') exclude = ('user', 'est_physique') # blabla fields declaration def is_valid(self): pass and edit view: class EditView

Django: Downloading uploaded files

我的梦境 提交于 2019-12-13 12:44:52
问题 I have form details in this question Django: Adding files to a form gives multiple argument error How to download the uploaded file. When i go to edit view of the form, i can see uploaded file url, but its not downloading. What setting to be changed for development and production mode? Error upon clicking link: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/media/Certificate.docx Using the URLconf defined in tiktant.urls, Django tried these URL patterns, in this

Can Django admin handle a one-to-many relationship via related_name?

坚强是说给别人听的谎言 提交于 2019-12-13 11:55:16
问题 The Django admin happily supports many-to-one and many-to-many relationships through an HTML <SELECT> form field, allowing selection of one or many options respectively. There's even a nice Javascript filter_horizontal widget to help. I'm trying to do the same from the one-to-many side through related_name. I don't see how it's much different from many-to-many as far as displaying it in the form is concerned, I just need a multi-select SELECT list. But I cannot simply add the related_name

send email to bcc and cc in django

此生再无相见时 提交于 2019-12-13 11:53:17
问题 views.py if 'send_email' in request.POST: subject, from_email, to = 'Parent Incident Notification',user.email, person.parent_email html_content = render_to_string('incident/print.html',{'person':person, 'report':report, }) text_content = strip_tags(html_content) msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to]) msg.attach_alternative(html_content, "text/html") msg.send() The above is the view to send email.By that way i can send the html content along with