Django Admin Dashboard and Views - django

I am new to Django framework and Django Rest Framework. In views.py file, I have added two class based REST APIs, one is derived from generic.ListCreateAPIView and the another one is derived from generic.RetrieveUpdateDestroyAPIView. Similarly in Django Framework based web application, in views.py file I have added class based views derived from generic.ListView and generic.DetailView. My question is when executing localhost:8000/admin the app is displayed in the browser , I am able to do CRUD operations, would the admin dashboard actions call functions or API in Views.py file or not? In admin.py file we are registering only model objects.

Related

Is there any tool to automatically create template for model in django

I am new in django and I have some experience in Jsf within Netbeans.
In netbeans, when we have entity classes, it can automatically create jsf page for this entity classes to list, create and view.
Is there any tool to automatically create template for model in django?
There is Django admin which you can connect your models to:
Django admin
It's as simple as a line of code:
from django.contrib import admin
from myproject.myapp.models import Author
admin.site.register(Author)
And you can do all sorts of customizations.

Are Django forms ever used in Django Rest Framework?

The DRF tutorial includes the following line about DRF serializers vs Django forms:
The first thing we need to get started on our Web API is to provide a
way of serializing and deserializing the snippet instances into
representations such as json. We can do this by declaring serializers
that work very similar to Django's forms.
But from what I can see, it says nothing else about the relationship between forms and serializers.
Since DRF doesn't need the Forms' ability to render a model in a template, is it fair to assume that Forms have no purpose in DRF, and that serializers can handle all of the validation traditionally completed with forms?
If so, when I'm building an API, can I forget about templates and forms entirely?
Django REST Framework is used for creating REST API's which send XML or JSON.
Django Forms is used for creating HTML forms based on a given model.
As the role of an API generally doesn't involve sending HTML, Django forms would not be used.

Django Forms without admin

I am learning Django, I saw so many videos of DJango.
I just wanted to know one thing that can we create an app (like login app, or contact app) without registering it into in admin (admin.py).
Off course it should have model etc to save the contact details or login details etc. Is it possible in Django ?
Just don't create your admin.py file or not register the model that you don't want to see there. Django admin is fully optional.

Dealing with Django model forms + REST Framework with Angularjs Single Page Application

I'm trying to implement a SPA in my existing Django project with Angularjs. I have setup the start of a API using Django Rest Framework to retrieve my data in angular.
Some of my django model forms have a lot of complexity in them and would love to somehow pass it to the client side.
I could be wrong here but since I'm setting this project up as a SPA, once I send the user to the project from my django urls.py, then the angular routing via $routeProvider take over and talk to all my angular stuff to get data (controllers, services, etc.,) via the REST api. This then prevents me from sending my form over via context.
Every example I've seen with angularjs and django forms always explicitly writes out each field in the form. Is there anyway for me to get my django model form that has a bunch of code in its __init__ method, over to the client side without having to set each field manually?
I've never tried this, but here's how I'd start on trying to do it.
You can use the in-built as_p(), as_ul() and as_table() methods of the form to pass the form HTML from the REST API, e.g.
class MyApiView(ApiView):
def get(self, request, format=None):
form = MyForm()
response['form_html'] = my_form.as_ul()
return Response(response)
You would then need to build the form skeleton and submit buttons in Angular, then insert form_html as the form body just as you would do in a standard django template.
Disclaimer: It's been a while since I've properly used django-rest-framework so the syntax in my example mught not be correct, but the basic idea is there

django-registration view customization

I'm using django-registration (see: https://bitbucket.org/ubernostrum/django-registration ) on one of my projects. The standard setup for the django-registration is to add a the code below in the urls.py file
(r'^accounts/', include('registration.urls'))
and also customize the templates in a folder called registration.
The code above is creating links to the registration, login and password recovery which is fine. But in my project there are some other functions I usually add to my views so if I just add the include('registration.urls') it appears that I have no way of customizing the views containing those django-registration forms.
Is there a way to call the forms used by the django-registrationin a view so I can add a few more things on those views ?
The registration form is provided by the registration backend. Check out registration.backends.default.DefaultBackend.
There's a method get_form_class(request) that returns the registration.forms.RegistrationForm class. All you have to do is create a new backend, inherit from DefaultBackend and override the get_form_class() method to return a new form class.
You can pretty much do anything by providing a custom backend, except changing the base behavior of the registration app. If you need to radically customize the views in a manner that providing a custm backend doesn't make the cut, then just create a authn or users app and import any bits from django-registration you find useful. You can, say, keep the default models and managers within the registration app namespace, but hook up a custom backend to your own internals in a new app.