Princode
To fix that, you should probably just first check if the user is logged in before you get whatever you want to get.
But I can't access the admin dashboard to log a user
Princode
Leonardo
Hi everyone! How to update images Gallery using Django? I'm trying with list, form and instance; but I'm not getting it. Are there any examples for me to improve my implementation?
.
I need help to create help desk project
Doragonsureiyā
I need help to create help desk project
No one can help you until you explain your difficulties.
.
Okay, I want to create agent predefined credential using Create custom command for agent dashboard. I have created user registration page which redirect to user dashboard but now I want connect agent dashboard using predefined credential
Da
i think you can use pipeline for the above
.
Where name and password is given
Ajeet
Where name and password is given
You need to share code
.
It's big file
Doragonsureiyā
It's big file
Rule 5️⃣: Never post walls of text or screen photos. Use paste bins like https://dpaste.org, https://hastebin.com, https://bin.kv2.dev or your favorite one!
.
there are two apps one is the user dashboard and 2nd is the agent dashboard. to access user dashboard you can use registration and login, but i want to create agent user name password using Django custom command s
.
how we can differentiate login system between agent and user
Charly
but depending on the role you can show or not sections
.
but the agent dashboard has a different one where they can see the user raises a ticket
Leonardo
how we can differentiate login system between agent and user
Verify the user type (is_staff, superuser,...)
.
superuser redirect to Django inbuilt dashboard
.
that i dont want
Charly
then change it
Leonardo
Verify the user type (is_staff, superuser,...)
You also create a new type of user
Charly
you are complicating yourself a lot for something that is very common
Charly
hacing diferent logins and users is just a lot of more work
.
then registration page would be different
.
but we can also use custom Management commands
Leonardo
We don't know how your gallery is implemented, we can't help
If you to can see my this part of the my project, please: https://github.com/LBarros77/raffles/tree/main/raffle
.
instead of registration page
Leonardo
You inserte the user type of the form explicit or implicit...
Leonardo
insert*
Charly
but we can also use custom Management commands
Ok so if you know how to implement what you are saying whats the issue?
.
we can use many way ...but my question is , can we can use the above method, if yes ...then how
.
i am trying whole day but not able to create
Charly
we can use many way ...but my question is , can we can use the above method, if yes ...then how
What do you mean by "custom management commands"?
Charly
i am trying whole day but not able to create
Then better to show what you have done and what issues do you have
.
https://docs.djangoproject.com/en/5.0/topics/auth/customizing/
.
what if i want to predefine admin name and password in my code section but i dont want to use superuser
.
i dont want to predefine in setting file
.
.any way if anyone know please let me know
Charly
what if i want to predefine admin name and password in my code section but i dont want to use superuser
What do you mean by `prefedine adminname and password in my code", and please be specific
t
I am currently developing a Django app that involves individuals with their birth dates. The birth dates are stored in Gregorian format in Django. I use django-jalali-date to convert them to the Jalali calendar. Currently, I need to create a task or a view to list all individuals born today (for example, the 28th of Khordad, regardless of the year) or send them a message. However, the main concern is just listing the exact birth date including month and day. The challenge arises because of leap years and non-leap years, which makes filtering difficult due to a one-day discrepancy. Here is my sample code where I need to filter both leap and non-leap years simultaneously, or if I filter for non-leap years, it shows different dates: # birth_year not set in filters def people_by_month_day(request, month_slug, day_slug): jalali_month_fa = ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'] if month_slug.strip() in jalali_month_fa: month = jalali_month_fa.index(month_slug.strip()) + 1 day = int(day_slug) # Generate Gregorian dates for a normal year and a leap year normal_gregorian_year = jdatetime.date(1403, month, day).togregorian() leap_gregorian_year = jdatetime.date(1404, month, day).togregorian() # Find people with birth dates matching either normal or leap year converted dates people = Person.active.filter( Q(birth_date__month=normal_gregorian_year.month, birth_date__day=normal_gregorian_year.day) | Q(birth_date__month=leap_gregorian_year.month, birth_date__day=leap_gregorian_year.day) )[:20] context = { 'people': people, 'month': month, 'day': day, 'month_name': month_slug } return render(request, "person/people_by_month_day.html", context) else: return HttpResponseNotFound('<h1>Page not found</h1>') In this code, I either filter both years, such as for leap and non-leap years: people = Person.active.filter( Q(birth_date__month=normal_gregorian_year.month, birth_date__day=normal_gregorian_year.day) | Q(birth_date__month=leap_gregorian_year.month, birth_date__day=leap_gregorian_year.day) )[:20] Or I have to choose one: If I filter for non-leap years: people = Person.active.filter( Q(birth_date__month=normal_gregorian_year.month, birth_date__day=normal_gregorian_year.day) )[:20] It correctly filters only individuals born in non-leap years by month and day. If I filter for leap years: people = Person.active.filter( Q(birth_date__month=leap_gregorian_year.month, birth_date__day=leap_gregorian_year.day) )[:20] It correctly filters only individuals born in leap years and not those born in non-leap years. For example: 26 Khordad 1370 1371 ... 1380 1399 1402 and so on... This causes a one-day discrepancy in their exact birth date likely due to leap years. For instance, June 18th in two different years will differ if one is a leap year and the other is not: 18 - 6 - 1981 28 / 3 / 1360 18 - 6 - 2004 29 / 3 / 1383 What comes to mind is to create a temporary column in the Django filter called is_leap_year: birth_date | is_leap_year 2004/4/5 | true 2005/6/4 | false If it's a leap year, account for that extra day; otherwise, consider it a non-leap year. However, this query seems complex and may require using Where, Case, and annotation in Django. If there is a better method, please let me know.
Suryo Adhy Chandra
{% extends 'users/base.html' %} Login {% block content %} <form method="post"> <h1>SignIn</h1> {% csrf_token %} {{ form.as_p }} <button type="submit">Submit</button> if you don't have account yet: <a href="{% url 'register' %}">SignUp</a> </form> {% endblock %} Forbidden (403) CSRF verification failed. Request aborted. Help Reason given for failure: CSRF token from POST incorrect. In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django’s CSRF mechanism has not been used correctly. For POST forms, you need to ensure: Your browser is accepting cookies. The view function passes a request to the template’s render method. In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL. If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data. The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login. You’re seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed. You can customize this page using the CSRF_FAILURE_VIEW setting. i don’t understand, why it doesn’t work
it seem you reload the page that contain POST method?
Nani
ValueError: Cannot assign "<django.contrib.auth.models.AnonymousUser object at 0x000001EA2C406310>": "Comment.author" must be a "UserProfile" instance. i tried so many ways but i didnt get it.
DV
How to fetch user input data from database using filter method?
DV
Pls help!!! 🙏🏻
Suryo Adhy Chandra
DV
see django doc, it simply explained
But i haven't seen about how to get specific data record using a single attribute value from database
Suryo Adhy Chandra
Ys
https://docs.djangoproject.com/en/5.0/ref/models/querysets/#pickling-querysets
Ex097
Hi All How are you? I am new on Django, can you give me a roadmap for learning, I have experience in Laravel
Ex097
And best wishes
Tobi
But I can't access the admin dashboard to log a user
You should check your views.py. You just have accessed a User object by using request.user or request.user.id
jj
How do I give a docker based project it’s own url after hosting it on the server?
Anonymous
You're using sessions to create a shopping cart. You have a Product model and a Variant model, where you specify the color and size of your products in the Variant model. This approach allows you to have products with different colors and sizes, as well as different prices. Is this the correct method according to you?
Anonymous
During implementation I'have many difficulties. It is my first experience with e-commerce site
Ахмед
Hello everyone. Need help, can you please help. I am doing a layout task to generate the final pdf file after submitting the application. The layout is formed using the Django Template Language. There was a problem with one piece of code. In general, I have 3 checkboxes, 2 checkboxes (2.1 and 2..2) they are in one object, and 2.4. in another. I need 2 checkboxes (2.1 and 2..2) put them in a separate loop inside the current loop so that they are visible in the code, since when selecting a checkbox on the site in the final pdf version, it does not mark them as selected. It's a pity you can't throw a photo into this conversation, if suddenly someone understands, please unsubscribe in the bos, I'll send a photo of the task so that it's easier for you to figure it out. A piece of code : {% for DUTY in DUTY__objects %} <<input type="checkbox" {%if FEE.THE NUMBER OF THE CHECKPOINT.2_1 or DUTY.THE NUMBER OF THE CHECKPOINT.2_2 or DUTY.2_4 %} checked {% endif %}>The fee was paid under the sub -item <input type="radio" name="duty_{{forloop.counter}}" {% if FEE.THE NUMBER OF THE CHECKPOINT.2_1 %} checked {% endif %}>2.1 <input type="radio" name="toll_{{forloop.counter}}" {% if TOLL.THE NUMBER OF THE CHECKPOINT.2_2 %} checked {% endif %}>2.2 <input type="checkbox" {%if FEE.2_4 %} checked {% endif %}>2.4 {% endfor %}
Mjuni
Hi All How are you? I am new on Django, can you give me a roadmap for learning, I have experience in Laravel
Use mosh hamedani " the ultimate django series"
vaishnav
Css cheat sheet
Wanda
I am working on a django celery aws s3 project where while doing celery shared task I am getting file access denied what should I do?
Jussy
Hello Everybody, I'm having a small issue on django I got this error from one of my form : line 1025, in _get_flatchoices for choice, value in self.choices: ^^^^^^^^^^^^^ ValueError: too many values to unpack (expected 2) The form inherited from ModelForm. In the fields I have a choice field that's present. I would also like to clarify that when I create the project and all his component it was working fine and from
Kishan
I need to deploy the django rest project in the cpanel Any have idea about this?
Doragonsureiyā
Css cheat sheet
This is not a Django specific question, please delete your offtopic message. If it's a Python related question go to @Python group, otherwise please move to @PythonOfftopic group and ask there.
Abolfazl
Hi, can anyone suggest me an expert django course and a good beginner django course (just for reviewing)
Alex
corey Schafer