inline-formset

Inline formset in Django - removing certain fields

只愿长相守 提交于 2019-12-03 04:35:17
问题 I need to create an inline formset which a) excludes some fields from MyModel being displayed altogether b) displays some some fields MyModel but prevents them from being editable. I tried using the code below, using values() in order to filter the query set to just those values I wanted returned. However, this failed. Anybody with any idea? class PointTransactionFormset(BaseInlineFormSet): def get_queryset(self): qs = super(PointTransactionFormset, self).get_queryset() qs = qs.filter

Inline formset in Django - removing certain fields

时光毁灭记忆、已成空白 提交于 2019-12-02 17:45:20
I need to create an inline formset which a) excludes some fields from MyModel being displayed altogether b) displays some some fields MyModel but prevents them from being editable. I tried using the code below, using values() in order to filter the query set to just those values I wanted returned. However, this failed. Anybody with any idea? class PointTransactionFormset(BaseInlineFormSet): def get_queryset(self): qs = super(PointTransactionFormset, self).get_queryset() qs = qs.filter(description="promotion feedback") qs = qs.values('description','points_type') # this does not work return qs

Django: how to display form errors for each model object in a inline formset

孤者浪人 提交于 2019-11-30 15:27:00
问题 I have a author model and a books model. A user can modify properties of all the books from a given author. I want to be able to display errors for each individual book rather than have all the errors listed on the top, How can I do this? MODELS from django.db import models from django.forms import ModelForm, Textarea from django import forms class Author(models.Model): fname = models.CharField(max_length=100) lname = models.CharField(max_length=100) def fullname(self): return '%s %s' % (self

Using django-dynamic-formset with CreateWithInlinesView from django-extra-views - multiple formsets

血红的双手。 提交于 2019-11-30 00:54:42
I got 3 models: class Client(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=40) class Phone(models.Model): number = models.CharField(max_length=10) client = models.ForeignKey(Client) class ClientEmail(models.Model): client = models.ForeignKey(Client) address = models.EmailField(verbose_name='Email') one form and two inline formsets: class ClientForm(ModelForm): class Meta: model = Client class PhoneFormSet(InlineFormSet): model = Phone extra = 1 class EmailFormSet(InlineFormSet): model = ClientEmail extra = 1 view: class ClientCreateView

How to create an inline formset for a reverse foreign key relationship

谁都会走 提交于 2019-11-29 17:29:23
I have a Property Model as follows = class Property(models.Model): property_type = models.CharField(max_length=255, default='Apartment') specifications = models.CharField(max_length=255, default='Basic') built_up_area = models.FloatField(max_length=6, null=False, default=0) total_area = models.FloatField(null=False, default=0) number_of_bedrooms = models.CharField(max_length=3, default=1) number_of_bathrooms = models.CharField(max_length=3, default=1) number_of_parking_spaces = models.CharField(max_length=2, default=0) address_line_one = models.CharField(max_length=255, null=False) address

Using django-dynamic-formset with CreateWithInlinesView from django-extra-views - multiple formsets

丶灬走出姿态 提交于 2019-11-28 21:39:20
问题 I got 3 models: class Client(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=40) class Phone(models.Model): number = models.CharField(max_length=10) client = models.ForeignKey(Client) class ClientEmail(models.Model): client = models.ForeignKey(Client) address = models.EmailField(verbose_name='Email') one form and two inline formsets: class ClientForm(ModelForm): class Meta: model = Client class PhoneFormSet(InlineFormSet): model = Phone

inlineformset_factory create new objects and edit objects after created

旧巷老猫 提交于 2019-11-28 18:27:23
In the django docs, there's an example of using inlineformset_factory to edit already created objects https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-formset-in-a-view I changed the example to be this way: def manage_books(request): author = Author() BookInlineFormSet = inlineformset_factory(Author, Book, fields=('title',)) if request.method == "POST": formset = BookInlineFormSet(request.POST, request.FILES, instance=author) if formset.is_valid(): formset.save() return HttpResponseRedirect(author.get_absolute_url()) else: formset = BookInlineFormSet(instance

inlineformset_factory create new objects and edit objects after created

£可爱£侵袭症+ 提交于 2019-11-27 11:34:22
问题 In the django docs, there's an example of using inlineformset_factory to edit already created objects https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-formset-in-a-view I changed the example to be this way: def manage_books(request): author = Author() BookInlineFormSet = inlineformset_factory(Author, Book, fields=('title',)) if request.method == "POST": formset = BookInlineFormSet(request.POST, request.FILES, instance=author) if formset.is_valid(): formset.save()

Creating a model and related models with Inline formsets

大兔子大兔子 提交于 2019-11-26 21:18:55
[I have posted this at the Django users | Google Groups also.] Using the example in the inline formset docs , I am able to edit objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for creating new objects using inline formsets, but have been unable to clear my head enough to bring out a working view for this purpose. Using the same example as in the above link, how would I go about creating a new instance of an "Author" model together with its related "Book" objects? priestc First, create a Author model form. author_form = AuthorModelForm()

django class-based views with inline model-form or formset

放肆的年华 提交于 2019-11-26 08:43:59
问题 I have the following models: class Bill(models.Model): date = models.DateTimeField(_(\"Date of bill\"),null=True,blank=True) class Item(models.Model): name = models.CharField(_(\"Name\"),max_length=100) price = models.FloatField(_(\"Price\")) quantity = models.IntegerField(_(\"Quantity\")) bill = models.ForeignKey(\"Bill\",verbose_name=_(\"Bill\"), related_name=\"billitem\") I know that this is possible: from django.forms.models import inlineformset_factory inlineformset_factory(Bill, Item)