Just god
Can anyone help me?
Muflone
you talk like i don't have research
Your is a complex question involving a lot of things. Learn Django and create every needed part to do that. If you have a concrete question ask your doubt
Ali
Hello guys I wanna make a bidirectional relation between two class model in django For example: A foreign key which shows the author And a many to many which shows all books of an author Is this design correct?
Анатолий
Hello guys I wanna make a bidirectional relation between two class model in django For example: A foreign key which shows the author And a many to many which shows all books of an author Is this design correct?
You can simply use foreign key for author in the book model. And if you need, for example, to get all the books of the author AUTHOR_NAME, you can use ModelName.objects.filter(): author_books = Book.objects.filter(author=AUTHOR_NAME) Or, if a book may have several authors, use ManyToMany field (inside one of the models. It depends on your needs where you should to add the field – into Author model or Book model. But technicaly, I think, there's no a lot of difference) If you perform ManyToMany field, you also will be able to get a value of the outer model An example: - We add ManyToMany field into Author model. ... books = models.ManyToMany(to=Book) ... - And whenever you need to get an author of a book, you can simply use the lowercased name of the author model. In this case Book model will have automatically a field "author" which is containing an id of the author whom the book belongs to. books_by_AuthorName = Book.objects.filter(author=AuthorName) (Notice, that we haven't define "author" field in Book model, it refers to an object of Author model) (Maybe I made some little mistakes in my description, take a look at the errors you get in the process, they are really helpful and sometimes tell you about your models more than you can imagine 😅)
Anonymous
If i use User.objects.get() is it safe?
if the username is not there in the User, then it will return an error, So better use User.objects.filter(), then check whather the object is exists with with exists() function
KingFx
guys! i implementing authentification process with django I want to give acces to certain ressources in a web app , but users should have an opening session I want to know how I can redirect users to the prevous url after login
Ravikumar
how to add add extra field to the ContentType model django
Anonymous
Can I use Django forms to create drf serializers?
Charly
DRF has its own serializers
Anonymous
DRF has its own serializers
So I can't use forms instead of models when creating serializers?
TonFutures 💎
Hi Can anyone help me?
Doragonsureiyā
Hi Can anyone help me?
No one can help you until you explain your difficulties.
TonFutures 💎
from django.contrib.auth.models import User from django.contrib.auth.backends import BaseBackend class CustomBackend(BaseBackend) : def authenticate(self, request, username = None) : try : user = User.objects.get(username = username) return user except User.DoesNotExist : return None setting.py : AUTHENTICATION_BACKENDS = [ 'd1.custom_backend.CustomBackend', 'django.contrib.auth.backends.BaseBackend' ]
TonFutures 💎
I create custom authenticate
TonFutures 💎
from django.contrib.auth import login, authenticate def SignIn(request) : user = authenticate('gg') print(user) form = MyForm() return render(request, 'login.html', {'form' : form})
TonFutures 💎
But when i print user It returns None
TonFutures 💎
'gg' is present in my auth_user table, in field username
Caleb
'gg' is present in my auth_user table, in field username
how can it authenticate with out the password?
TonFutures 💎
Caleb
I create custom authenticate
but you are importing authenticate from django.contrib.auth
Caleb
I create custom authenticate
make sure to import your custom implementation, name it differently to not get confused
TonFutures 💎
TonFutures 💎
AUTHENTICATION_BACKENDS = [     'd1.custom_backend.CustomBackend',     'django.contrib.auth.backends.BaseBackend' ]
TonFutures 💎
It work, i'm sure Because i set print(1) in authenticate and it work
TonFutures 💎
from django.contrib.auth.models import User from django.contrib.auth.backends import BaseBackend class CustomBackend(BaseBackend) :     def authenticate(self, request, username = None) : print(1)         try :             user = User.objects.get(username = username)             return user         except User.DoesNotExist :             return None
Zhaks
Does .first() method in Django ORM hits db?
Charly
Does .first() method in Django ORM hits db?
If not, how is it going to get the data?
Ayaz
Can anyone help me to run my project giving some error?
uquacore
If I have a django all-auth module that is responsible for signing a user up via GitHub in my Django project, am I supposed to change my basic registration and login to all-auth ones instead of the standard Django or isn't it necessary?
uquacore
You can have both , Do you need email auth as well?
I've already realized it using Django
uquacore
It seems to me I will have to change everything I have for now because of social auth I am trying to make
uquacore
You can have both , Do you need email auth as well?
I don't have email verifation, though. So that's the reason I assume I'd better edit the project authentication right now, when the project is not so comprehensive
Kumar Shreyansh
Hi all, what is the best way to do cache management in django? My application keeps malfunctioning unless cache is cleared every time
Koen de
Steve
Please help my issue : Collecting mysqlclient Using cached mysqlclient-2.2.0.tar.gz (89 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error
Koen de
Please help my issue : Collecting mysqlclient Using cached mysqlclient-2.2.0.tar.gz (89 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error
You might need to install some pre-requisites. The error you showed us is not the complete error is it? Please note; https://stackoverflow.com/a/74236191
शिवांजली
ilham
how to create a form with fields from different model?
Targoon
how to create a form with fields from different model?
in the class, use instance of class nameOfClass(Forms.form) instead of forms.Model
Targoon
but seriously, why people do not seaech in google
Ohama |
Is there plugin validator based on text similarity?
Максим
DRF class Book(Model):     name = CharField(max_length=15, unique=True) class BookSerializer(ModelSerializer):     class Meta:         model = Book         fields = ('name',) class AuthorSerializer(ModelSerializer):     book = BookSerializer() # need validation of json when create     class Meta:         model = Author         fields = ('id', 'book') How to disable unique validation of the field "name" in AuthorSerializer, in nested BookSerializer? I do not want to change model Book or BookSerializer. What I do: I try to create an Author with get_or_create Book. If I use get_or_create, I do not need unique validation
C
Hi all. I’m just starting out to learn Django. But I’m not understanding it. Are there any resources to revise my python. And also any resources to help a beginner Django learning. General advice on resources, books, etc that will be helpful. If there’s anyone here who would like to mentor me and give me what o study each week, and whom I can report progress to, I will be Glad.
T
Hello, I have my app "base" so the admin url is localhost/admin/base .. i dont need the page localhost/admin that list all the apps inside my project.. How can I do to make the user reach admin/base instead /admin after login as admin at the url localhost/admin? Thanks a lot.
Anonymous
pls how can i fix this error my code link is https://linkode.org/#9b5wxCSbiWnr2f0Iw05xn
Anonymous
error message is this ImproperlyConfigured at /companies/ Could not resolve URL for hyperlinked relationship using view name "campany-details". You may have failed to include the related model in your API, or incorrectly configured the lookup_field attribute on this field.
Anonymous
🙏 i need the help what am doing is to create user from my model
Anonymous
using some of the fields in my model
Pradheep
from .models import Customer, Product, Order ImportError: attempted relative import with no known parent package i am getting this error could some help me to fix this
Doragonsureiyā
from .models import Customer, Product, Order ImportError: attempted relative import with no known parent package i am getting this error could some help me to fix this
Please provide a full explanation including all the details that you consider relevant. Your statement is too broad and there is no clear way to answer you, you have to explain: - what you're doing - what you're expecting - what you're using - where you're running the script - what Python version you're using - what packages and their versions you're using - and the most important thing: show the code YOU wrote (read rule 5️⃣ for that) and more details, that way your chances to get help will increase
Kumar Shreyansh
from .models import Customer, Product, Order ImportError: attempted relative import with no known parent package i am getting this error could some help me to fix this
You need to provide package name as well. It means that the import statement will be: from <app_name>.models import <model_name>
TonFutures 💎
Hi What is the most reasonable way to create a signup page?
Kumar Shreyansh
Hi What is the most reasonable way to create a signup page?
I think it can be using Abstract User base class and Signup Class Views
Ohama |
Hi, anyone know how to redirect a view base on function that required permission/authorized authentication to redirect to non login view.? I have redirect with decoreator in setting but it add /next url
Kumar Shreyansh
Hi, anyone know how to redirect a view base on function that required permission/authorized authentication to redirect to non login view.? I have redirect with decoreator in setting but it add /next url
Hi, yes. You need to put app_name parameter in urls.py file. And then redirect to the non login view using {% url '<app_name>:<url_name>' %}
Kumar Shreyansh
That not work because it always add next to url
I am using it everywhere in my application
Kumar Shreyansh
In def login(request), put return redirect above url format. Put app_name='some name' in urls.py file above urlpatterns in your django app urls.py file, not in global urls.py file
Ohama |
I am using it everywhere in my application
It always add next parameters url when i put non login url on login_required
Kumar Shreyansh
It always add next parameters url when i put non login url on login_required
Please share your code via github link or pasting service
Kumar Shreyansh
Please share views.py, urls.py files
Ohama |
Please share your code via github link or pasting service
There is no detail need to know about it because i just add permission to root url when clients visit the root url i want to redict to non login view then django always add /next parameters. Let say my non login view is contact info.
Demsy
I want to display a message using Message.info But I get this error SafeString object has no attributes 'info'