Django-recurrence with Vuejs - django

I am using a django backend with a vuejs frontend and I am trying to get the django-recurrence form to work inside a vue template with no luck. I am trying to generate recurrences to send to the backend. Is there a way to make this work or would I need to create my own form just for generating the recurrence field?

django-reccurence widget relies heavily on the django templating system. The init file for the widget makes reference to django directly. If you front end is not using django, I would self bake or rely on a JS widget not tied to django.
I have not tested this with django-recurrence, but in theory you should be able to use any UI widget since the widget and django-recurrence are using the same standard.
https://github.com/collective/jquery.recurrenceinput.js/tree/master

Related

Django model React

I'm trying some Django + React stuff and I'm a bit confused with the particular role of Django model in this scheme.
As I can understand Django model provide smooth way to create some typical forms by users of the site (please correct me). And I can't feel the edge of what should be hardcoded and what I need to store in model.
In case of React (I'm trying to connect react with django through api via djangorestframework) should I create a model for Header? And store bg image with it and my slogans. I feel it's should be purely in frontend. But next section with 3 typical screens (they will be listed horizontally and swap each other). They are just copy of each other with different data (title, bg, fg, text, link), for me it seems closer to model usage. But model initially empty and if I want to get this data from model I firstly need to somehow store this data to model.
So in general my question is what the right cases for using Django models and when it's no needed. And if it possible with applying to my example to better understanding for me )
ofc I searched this info widely but so far can't create clear understanding by myself.
Thanks )
You might actually be in search of a headless CMS.
To combine React and Django and still use a CMS to allow administrating text blocks and images, Django Wagtail's StreamField is a good choice.
https://docs.wagtail.io/en/v2.0/topics/streamfield.html
See for example our company's homepage: https://www.blu-beyond.com. It runs on Django Wagtail, having JS animated text blocks that are administered in the CMS (just jQuery and other JS libs, no React, in this case).
Django Wagtail offers a JSON API, as well, that can be used in React:
https://docs.wagtail.io/en/v2.8/advanced_topics/api/v2/usage.html#fetching-content
It also offers a GraphQL API.

Is Django using any front end framework or library?

Is Django Admin validated their data to client side or server side ?
And when we using Django Forms then is still need to use front end framework for data validations ?
It depends, if you use Dajgno-rest-Framework and if you want the front-end Framework to have all those things, then the ideal would be Angular, from version 2 onwards:
Ajax calls: HttpModule or from version 6 HttClient.
It helps you reuse components.
It facilitates the validation of forms (With html5)
Structure code, quite clean.
Animations, if the framework covers it.
Otherwise, django's own template system offers many advantages to work, you can combine using Jquery. If you use Angular Js (Old version) you should be careful with possible conflicts, for example in the interpolation of double braces {{}}.
Yes Django using jQuery library and for custom validations we can use jQuery to validate data.
Here are some links
Add jQuery in django admin site
Adding inlines using of custom jQuery

When to use Angular with Django?

I have a pretty basic question.
Consider a CRUD web application built on Django. You have templates that render data. Those templates might have forms where you submit data to the backend, and that might reload the page to display changes. Sometime, you can make those requests over AJAX, for example when you need to update data on the UI. You can also submit forms with AJAX and update the HTML with it.
On the other hand you have single page applications. You serve a static file, and there is no reload of pages. You have data that comes from an API and populates some front-end template.
What are some guidelines for when to use what? Not in a mutually exclusive way, but within one Django project, what are some reasons/considerations to use a Django template/forms/AJAX approach and when to use Angular?
Thank you.
Something to consider is how "interactive" you want the client-side to be.
I am in the process of converting an existing Django app to use Angular (and django-rest-framework). The app was highly interactive and relied on a lot of custom JQuery to get various widgets working just right. JQuery's constant looping through the DOM made it pretty slow. I am finding that using Angular instead of JQuery is much faster.
So if you have a lot of complexity in the front-end, I would recommend Angular.

Internal app without public URL in Django

The ultimate aim is to have a flexible mechanism in a Django web app for rendering PDF files. To achieve this I have designed a mechanism using Jinja2 for templating a TeX input file with a given dictionary. The template is served by a custom jinja loader via the Django ORM. The TeX file is then compiled using pdflatex.
I have made a separate app in Django in which the model for the LaTeX templates is defined. In this app there is a class in which the rendering takes place. In the end a HttpResponse object is created with which the PDF is returned.
For me this sounds like a classical Django view: it takes a request and delivers a response. However I would like to prevent anybody from using this view to generate arbitrary PDFs just by calling an URL.
How do I do that? Write a view without referencing it in the URL configuration and then call it directly from other views?

Backbone.js and Django (Without Tastypie)

I'm using Django for my site and trying to incorporate backbone.js. Backbone encourages using Tastypie - but I would rather not. Is there a way to use backbone.js and django without tastypie? Are there any examples out there of how to do this?
I've been were you are. Needed to just make a custom API for backbone to read for the specific instances.
All that really means, is making custom views in your views.py and attaching them to custom urls in urls.py for backbone. Your views will have to return a JSON version of the object or objects
So you end up with friendly looking urls that backbone likes
For example if I had a model of boxes and I want to write a url and a view that sends all the boxes in my database to my frontend delivering them to backbone - I could make a url like this /api/v1/box/all/ really anything you want. In your view you just need to remember to return JSON.
Remember - you need update views to to update from backbone syncings (tastypie PUTS)
something like /api/v1/box/3/update?updatedinfodata
Let me know if you would like me to expand or show some code.
It is possible to bot use TastyPie and just build your own API.
You just need to know Backbone sends to the API and data it expects to receive.