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

Render croppie again #12

Open
yash-malviya opened this issue Jun 30, 2020 · 5 comments
Open

Render croppie again #12

yash-malviya opened this issue Jun 30, 2020 · 5 comments

Comments

@yash-malviya
Copy link

Hi ! i am using croppie and its working fine. I was trying to add some functionality like clicking on a button gives me the cropped image [working fine] but i also wanted to add a button which takes be back to crop the same uploaded image. is there a way to render croppie again without actually refreshing the page.
ThankYou. ;)

@dima-kov
Copy link
Owner

dima-kov commented Jul 3, 2020

I need more details to say smth. Could you paste the code to reproduce?

is there a way to render croppie again without actually refreshing the page.

I think, yes, you could do this with js, but, once more, I need more details.

@dima-kov
Copy link
Owner

dima-kov commented Jul 3, 2020

Also, take a look on this fork: https://github.com/strycore/django-croppie

@yash-malviya
Copy link
Author

Sorry but i am no longer working on that. but i do need help in Saving the image

class FiraCreateView(CreateView):
    model = Fira
    form_class = FiraForm
    template_name = 'create.html'
    success_url = '/'

above view is given in the example file

but i want the same functionality [saving the cropped image to my models] using something like this

def home(request):
    if request.method == 'POST':
        # i want to get the cropped image here and save it to the model
        else:
            return HttpResponse('<h1> Opps ! An Error ! Form rejected ..  ;( </h1>')
    if request.method == 'GET':
        form = CroppieImageForm()
        posts = 
        profile =
        return render(request, 'User/home.html', {
            'posts': posts,
            'profile': profile,
            'form': form
        })

So the reason why i wanna do something like this is because i m not adding a new row in my database my profile database already exists and i only wanna update the picture field.

Models.py

class Profile(models.Model):
    CHOICES = [
        ('Male', 'Male'),
        ('Female', 'Female'),
    ]
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    full_name = models.CharField(max_length=50)
    dob = models.DateField()
    picture = models.ImageField(upload_to='ProfileImages/',  blank=True)
    gender = models.CharField(max_length=6, choices=CHOICES)

    class Meta:
        db_table = 'profile'

    def __str__(self):
        return self.full_name

Forms.py

class CroppieImageForm(forms.ModelForm):
    image = CroppieField(options={
            'viewport': {
                'width': 250,
                'height': 250,
                'type': 'circle',
            },
            'boundary': {
                'width': 500,
                'height': 300,
            },
            'showZoomer': False,
        }, label=''
    )

    class Meta:
        model = Profile
        fields = ('picture',)

@shalltell
Copy link

Also, take a look on this fork: https://github.com/strycore/django-croppie

I added this as a PR. It has conflicts, but have tested with -X theirs strategy without issues.

@dima-kov
Copy link
Owner

dima-kov commented Apr 7, 2022

Regarding the view:

def home(request):
    if request.method == 'POST':
        form = CroppieImageForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save()
            return redirect('/success')
        else:
            return HttpResponse('<h1> Opps ! An Error ! Form rejected ..  ;( </h1>')
    if request.method == 'GET':
        form = CroppieImageForm()
        posts = 
        profile =
        return render(request, 'User/home.html', {
            'posts': posts,
            'profile': profile,
            'form': form
        })

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

3 participants