I am quite new to django, I know little terms... so it will be appreciated if you would answer more specifically how to implement. <3
I am working on a web development assignment about an image sharing platform. functionality involves users upload, download, delete and search images, etc.
recently I have implemented 'allauth' plugin to my site so that users can login in to the site, also I created an app called 'AllImages' with a model - 'Image'.
MY QUESTION IS:
How can I link the users to 'AllImages' and 'Image', so that the system knows who uploaded a particular image.
because I want to only let the uploader himself being able to delete his image
I really know nothing about the plugin, its just done by someone haha....
this is the allauth plugin
In your Images model add a foreign key field to user.
from django.contrib.auth.models import User
Further you can query something like..
Images.objects.filter(user=logged_user) to get all images of this particular user.
Django auth User
Related
I'm trying to learn how to use Authy/Twilio in a new Django app. I found this helpful demo application https://github.com/TwilioDevEd/account-security-quickstart-django which I was reading through to see how it all worked. I noticed in the settings.py file they referenced a custom user model, which I found here. The custom model looks very basic and doesn't have much of the info stored in the regular user model.
My questions are:
Is it required to use this custom model or can you somehow add the
required info into the existing/default user model?
How would this integrate with Django apps using something else (like
ldap) as the backend instead of the django db user model?
My english is not perfect thus the title is confusing. I don't know how to really put what i want to say. Anyway, I have a django 1.11 application that is running well. Wrote admin.py for some apps and a bunch of admin forms overridden. But client said he wants a different way of doing things (instead of admin carrying out the task, everyone registered on the app can). I already have a dashboard for those users and he wants the admin forms to be in that dashboard as opposed to the /admin default dashboard.
I failed to find such a thing in the documentation, I think. But basically, I want some forms to be avalibale, as they are, in the client dashboard? Is that possible?
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.
Im really confused about what is all i need to consider for creating a django aplication with almost similar functionality to it's own admin.
The index page should deploy the list of models the user has access to modify or create...almost the same as when you put admin.site.register(MyModel) but with permission restriction. Im not sure how should i ckeck permissions, and show 1 ,2 or many "ModelAdmis" on my main page.
btw admin users are redirected to the admin index page, non-admins go to my page
Before you consider creating a django admin from scratch, you should read the answers to this question Django Admin app or roll my own?
I couldn't find any resource on how to create a django admin from scratch, but here's what you should do if this is your first time overriding a framework's functionality (in my humble opinion):
Understand and make sure you are comfortable with the django admin app
start from the docs https://docs.djangoproject.com/en/1.7/#the-admin
Head over to the django admin app source code so you can start reading the internals of the functionality you want to implement/override in your new admin app.
source code can be found here https://github.com/django/django/tree/master/django/contrib/admin
(this may involve reading other apps source code too)
After those two steps you should have an idea on how the admin app is implemented and it's dependencies, then you can start creating your custom admin app.
an example on how this may go can be found in this qestion:
How to override Django admin's views?
If you are building something new, try to separate the UI from the backend. You can build your UI using react, angular or whatever and interact with django using the API. To build the API you can use the Django Rest Framework.
Don't use the Django Admin as a public interface. Use that only for the admins!
If you start to use the Django Admin as interface for your public site, you'll fight with the package to tailor and secure the views to avoid destructive actions. What happen if you forget a readonly field? What if the user deleted something ON_CASCADE?
Building the UI you are totally free and you can customise easily everything without fighting the django admin package (it's awesome package but is not provided for public use)
I am new to Django and trying to create a registration form for users. I want users to upload there image during signup. After some research I got django-avatar and easy thumbnail as way to go, am I correct? So I went ahead with django-avatar but I am confused how to add a form field to userprofile that talks to django avatar. Am I in correct path or should I use some other plugin for uplaoding an user image. If Django-avatar is the way to go how should I create a form field for image and how my view look like?
Try using Formsets with the form set to avatar.forms.UploadAvatarForm