django-forms

Update in three models at the same time in form_valid django

…衆ロ難τιáo~ 提交于 2020-01-06 21:07:18
问题 I have three models, Propietario, Administrador and Encargado. And I have three forms with ModelForm calling each of these models. The forms may to have three options depends of the user does: If user picked option A, will display three forms where can fill different data for each form If user picked option B, will display two forms, where the data filled in the form FormPropietario will save in Propietario model and automatically in Administrator model the same data. And the second form

Different implementations for Autocomplete-light

*爱你&永不变心* 提交于 2020-01-06 20:19:28
问题 I was able to implement the autocomplete-light function using a class based view format: class UserAccountsUpdate(UpdateView): context_object_name = 'variable_used_in `add_user_accounts.html`' form_class = AddUserAccountsForm template_name = 'add_user_accounts.html' def add_user_institution_details(request): ###code### With this form: class AddUserAccountsForm(autocomplete_light.ModelForm): required_css_class = 'required' name = forms.CharField( required=True, widget=autocomplete_light

Different implementations for Autocomplete-light

只谈情不闲聊 提交于 2020-01-06 20:16:36
问题 I was able to implement the autocomplete-light function using a class based view format: class UserAccountsUpdate(UpdateView): context_object_name = 'variable_used_in `add_user_accounts.html`' form_class = AddUserAccountsForm template_name = 'add_user_accounts.html' def add_user_institution_details(request): ###code### With this form: class AddUserAccountsForm(autocomplete_light.ModelForm): required_css_class = 'required' name = forms.CharField( required=True, widget=autocomplete_light

Adding a FileField to a custom SignupForm with django-allauth

被刻印的时光 ゝ 提交于 2020-01-06 19:55:27
问题 I have the following custom SignupForm (simplified, works perfectly without my_file): class SignupForm(forms.Form): home_phone = forms.CharField(validators=[phone_regex], max_length=15) my_file = forms.FileField() def signup(self, request, user): new_user = ReqInfo( user=user, home_phone=self.cleaned_data['home_phone'], my_file=my_file, ) new_user.save() In models.py: class ReqInfo(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True) home_phone =

django: SplitDateTimeWidget ignores date_format

风格不统一 提交于 2020-01-06 19:41:35
问题 I am trying to use the SplitDateTimeWidget but want it to accept date in day - month - year format. from django.forms.widgets import SplitDateTimeWidget class EventForm(forms.ModelForm): class Meta: model = Event widgets = {'start': SplitDateTimeWidget(date_format='%d/%m/%Y')} The SplitDateTimeWidget accepts a date_format argument, which I expect to be used to validate the date input but it isn't. The default widget is correctly replaced but it ignores the date_format and insists on

Django: TemplateView or FormView?

纵然是瞬间 提交于 2020-01-06 14:26:32
问题 I am currently trying to bring my function-based view into a class-based view. The question I am currently struggling with is if I should either trying to move it into a TemplateView with FormMixin or in a FormView with ContextMixin. Do you have any tips on how to decide what's best? def event_detail_view(request, event, organizer): queryset = Event.objects.filter(organizer__slug=organizer) event = get_object_or_404(queryset, slug=event) tickets = collect_all_tickets(event, organizer)

How can I write a unittest to check that a django model form is valid?

馋奶兔 提交于 2020-01-06 11:51:39
问题 I am trying to test that a model form is valid. In the test function, I create the two models that feature in my custom form. I add the data to fill the form's required fields. When I run the tests and call is_valid() on the form, the test fails and the form gives the error that the option that I have added is not one of the available choices . This suggests to me that I have incorrectly added the Option instance to the form or to the test. I am unsure how. How can I make the model form valid

How to fill a form field based on the value of an autocomplete field in Django template using Ajax+jQuery

落爺英雄遲暮 提交于 2020-01-06 08:05:44
问题 In my application, I am using Ajax+jQuery to populate the unit of measure field based on a product selected by the user using a dropdown. In my products model, each product has been assigned a unit of measure and is picked up to autofill the unit field during order creation. I am using jQuery to pick up the product from select field and capturing the event using .on('change') event. Following are the objects: models.py Model : Product class Product(models.Model): product_id = models

RuntimeWarning for DateField in Django

北城以北 提交于 2020-01-06 07:56:19
问题 Hello i'm using dates for search queries. But i am getting runtime error. RuntimeWarning: DateTimeField Jobs.job_created_on received a naive datetime (2019-01-17 00:00:00) while time zone support is active. Views.py class JobListView(LoginRequiredMixin, generic.TemplateView): template_name = 'admin/jobs/job.html' def get(self, request, *args, **kwargs): context = super(JobListView, self).get_context_data(**kwargs) if 'status' in request.GET: form = JobSearchForm(request.GET) if form.is_valid(

Django FilteredSelectMultiple Right Half Does Not Render

筅森魡賤 提交于 2020-01-06 07:11:57
问题 I have the same problem as [@DHerls][1], but the given solution did not work for me. Django FilteredSelectMultiple not rendering on page Other similar questions with solutions I tried: Django FilteredSelectMultiple widget rendered with bootstrap Django admin's filter_horizontal not working Uncaught ReferenceError: django is not defined The problem is that only half of the FilteredSelectMultiple shows up: Things I have tried: syncdb checking that jQuery is running checked for jQuery imports