Z
Z
zigen2015-06-29 12:25:01
JavaScript
zigen, 2015-06-29 12:25:01

Show CBV + Ajax Django example?

Good afternoon.
Does anyone have an example of class-based view + ajax? preferably, which was written by you, and not from the Internet.
I have, for example, such a model when registering a user.

class VendorProfile(models.Model):
    user = models.OneToOneField(User)
    org_name = models.CharField(max_length=50,blank=True)
    slug = models.SlugField(unique=True)
    city = models.CharField(max_length=30)
    description = models.TextField(blank=True)
    ....  
   kind_activity = models.ForeignKey(Activity)

I would like to do everything elegantly on the server side without creating a form, hardcoding in the view.

djbook.ru/rel1.8/topics/class-based-views/generic-...

It's very tempting to register via Createview and Ajax.
More interested in the frontend side.
Since it is not clear how to insert the form into the template in this case and where to send error messages.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2015-06-29
@mututunus

Something like this:

class RegistrationView(CreateView):
    def form_invalid(self, form):
        return JsonResponse({
            'status': 'error',
            'errors': form.errors,
        })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question