Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget not working with InlineFormSet #16

Open
yasmin-liban opened this issue Mar 22, 2021 · 0 comments
Open

Widget not working with InlineFormSet #16

yasmin-liban opened this issue Mar 22, 2021 · 0 comments

Comments

@yasmin-liban
Copy link

yasmin-liban commented Mar 22, 2021

I'm trying to use the module with an inlineformset_factory, my settings are as as follow:

models.py

class Products(models.Model):
...

class Product_Image(models.Model):
    product = models.ForeignKey('Products', on_delete=models.CASCADE)
    image = models.ImageField(null=True, upload_to=...)

forms.py

class ProductForm(forms.ModelForm):
   ...

class Product_ImageForm(forms.ModelForm):
    image = CroppieField()
    class Meta:
        model = Product_Image
        fields = '__all__'
        
ProductInlineFormSet = inlineformset_factory(Products, Product_Image,form=Product_ImageForm)

views.py

class NewProductView(LoginRequiredMixin, CreateView):
    model = Products
    form_class = ProductForm
    template_name = 'products/addProduct.html'
    login_url = reverse_lazy('users:login')
    # fields = "__all__"

    def get_context_data(self, **kwargs):
        context = super(NewProductView, self).get_context_data(**kwargs)
        if self.request.POST:
            context['product_formset'] = ProductInlineFormSet(self.request.POST)
        else:
            context['product_formset'] = ProductInlineFormSet()
        return context
    ...

template

...
                       {{product_formset}}
                        <div class="row">
                            <div class='col d-flex flex-row-reverse'>
                                <button class="btn btn-info btn-lg">Salvar</button>
                            <div>
                        </div>
                        <div style="width:50%">
                            <div id="cropper"></div>
                        </div>                        
                    </form>
                    {{ form.media }}
                    {{ product_formset.media }}
...

What I have when I open the page of the create view is a blank widget that wherever I upload an image does not update to crop the current image, like it would happen if it was in a normal form. I tried using a normal form and it worked perfectly but that is not my objective. It would be nice if in the future you added support to formsets and such.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant