The Inspired
I am trying to add new campaign
from what I understand, there is probably some data in campaign table already present. Try deleting all data from campaign table in your DB and then add a new one
Sousa
class CustomUser(AbstractBaseUser, PermissionsMixin): empresa = models.ForeignKey(Empresa, verbose_name='Empresa', on_delete=models.CASCADE) email = models.EmailField(unique=True) nome = models.CharField(max_length=100) is_admin = models.BooleanField(default=False, verbose_name='Admin') is_comum = models.BooleanField(default=True, verbose_name='Comum') is_staff = models.BooleanField(default=False, verbose_name='Staff') date_joined = models.DateTimeField(auto_now_add=True)
Sousa
Traceback (most recent call last): File "/Applications/MAMP/htdocs/ERP/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Applications/MAMP/htdocs/ERP/venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return super().execute(query, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.IntegrityError: NOT NULL constraint failed: app_usuarios_customuser.empresa_id The above exception was the direct cause of the following exception:
Sousa
"I am receiving this error, can you help me?"
Charly
And seems you are not providing a value for that field
Charly
At which file
Impossible to know you haven't shared anyd etail
Charly
but thats a general principle, so in every file
Oviyan S
Do you need entire code
Charly
Do you need entire code
no, the full error usually gives hints
Peter
Hey guys... I am mern dev looking to switch to django for backend. Any tutorials or suggested roadmap.?
Doragonsureiyā
Hey guys... I am mern dev looking to switch to django for backend. Any tutorials or suggested roadmap.?
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Ортонормированная
https://github.com/dura0ok/photocenter-django/blob/master/queries/views.py hi guys, give advice how refactor it
Amirhossein
Hey guys, im trying to use django and telethon. i want to simple thing's, get informations from bot and send them to web site. any advice or ideas?
Human
I I have started to create a webapp called TweetApp just for learning purpose, where users can tweet and like the tweets. So I want to check whether the tweet is liked by the logged in user. I'm using class based listview for that... I thought to do annotation. Or something else... Still clueles... Anyway to do that?
Manrahul
Anybody worked on GraphQL in django ?
Doragonsureiyā
Anybody worked on GraphQL in django ?
Please don't ask meta questions like: - Any user of $x here? - Anyone used technology $y? - Hello, I need help on $z! Just ask about your problem directly! If you don't know what to ask, please read: http://catb.org/~esr/faqs/smart-questions.html
Manrahul
I want to know how to use Graphql API in django with nextjs frontend
Mirco
I want to know how to use Graphql API in django with nextjs frontend
You can rely on Strawberry package for graphql APIs in Django https://strawberry.rocks/docs/integrations/django The in nextjs you just have to consume them
Dairon
Can anyone provide me feedback about the process to translate a Django's web page?? I have to do it in Spanish and English
Human
I have a home page which contains listview, so I need to add a form and share the values to backend. So how to do that in the same page using CBV?
Oviyan S
no, the full error usually gives hints
Here is the error TypeError at /admin/ Cannot mix str and non-str arguments Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 4.2.4 Exception Type: TypeError Exception Value: Cannot mix str and non-str arguments Exception Location: C:\Users\kaleeshwari\AppData\Local\Programs\Python\Python311\Lib\urllib\parse.py, line 130, in _coerce_args Raised during: django.contrib.admin.sites.index Python Executable: C:\Users\kaleeshwari\AppData\Local\Programs\Python\Python311\python.exe Python Version: 3.11.4 Python Path: ['C:\\Users\\kaleeshwari\\Desktop\\feedback\\FeedBackSystem', 'C:\\Users\\kaleeshwari\\AppData\\Local\\Programs\\Python\\Python311\\python311.zip', 'C:\\Users\\kaleeshwari\\AppData\\Local\\Programs\\Python\\Python311\\DLLs', 'C:\\Users\\kaleeshwari\\AppData\\Local\\Programs\\Python\\Python311\\Lib', 'C:\\Users\\kaleeshwari\\AppData\\Local\\Programs\\Python\\Python311', 'C:\\Users\\kaleeshwari\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages'] Server time: Fri, 10 May 2024 14:11:51 +0000
Oviyan S
Cannot mix str and non-str arguments
Can you explain in detail
clouded
Can you explain in detail
Have a look at the Traceback (which is not among the information you have shared).
Levitybot
I want to know how to use Graphql API in django with nextjs frontend
Both Django and NextJS provided both back and front end. So essentially you would just have two completly independent sites, and allow CORS from the Django API to the NextJS site. I'm not sure if this is really what you want to achieve? You could just use Django with React or Django with HTMX. Using NextJS and adding a second backend seems strange but I don't know your requirements.
Levitybot
Thanks, UUID should be generate unique. And I am adding new campaign, don't won't to update existing. I have tried by deleting db. And added some campaign. But after adding few campaign some where getting this same error. How the UUID will generate duplicate?
Perhaps try adding some print statements just before you add so you can see if the Id is already set somehow with an Id from a previous record. Maybe you need to blank it out if you are cloning an existing record.
Madhur
Okay, I will try thi
clouded
Ok
I have missed to write *not* when saying that it's *not* part of the information you shared.
Javlonbek Torajonov
good evening everyone
Oviyan S
When I create a new project. It shows the same error
Javlonbek Torajonov
i have a some bugs
Javlonbek Torajonov
3, in ‹module> from modeltranslation models import checksum, FieldTranslation, trans_attr, trans_is_fuzzy_attr ImportError: cannot import name 'checksum' from 'modeltranslation models' (C:\Users\HONOR\AppData\Local\Programs\Python\ Python311\Lib\site-packages\modeltranslation\models.py)
tan (θ)
share me your thoughts👍👍👍 I have a DRF project using jwt for authentication, and now I want to include Oauth, so which one of this approach is best? 1. let the user login/signup with the Oauth credentials and generate jwt token 2. use the Oauth login/logout logic directly Thanks🙏🙏
Levitybot
3, in ‹module> from modeltranslation models import checksum, FieldTranslation, trans_attr, trans_is_fuzzy_attr ImportError: cannot import name 'checksum' from 'modeltranslation models' (C:\Users\HONOR\AppData\Local\Programs\Python\ Python311\Lib\site-packages\modeltranslation\models.py)
Have you switched between machines and not installed the module into this machine virtual environment? You can use pip freeze to make a requirements.txt file to keep your virtual environments in sync if you go between machines
-sobhan
Hello my friends How is the architecture in Django and Rabbitmq
-sobhan
Has anyone ever done a project with Django and Rabbitmq?
Charly
Hello my friends How is the architecture in Django and Rabbitmq
Depends on the purpose of having a message broker
Ортонормированная
how use param in queryset in ModelMultipleChoiceField
Human
If you want to check user, why use list view? Just do the logic inside the function?
In list view it will show the list of posts the following people posted, and if I liked one of the post, I can see the I liked it
-sobhan
Depends on the purpose of having a message broker
Is it possible to explain more precisely?
Beka
No, after login only the users can see the post and like.
I would recommend to use: LoginRequiredMixin You can import like this: from django.contrib.auth.mixins import LoginRequiredMixin The above, if your approach is CBV In case, FBV: You can use decorator : @login_required and you can import from here: from django.contrib.auth.decorators import login_required Is this one of the solutions that helps to solve your problem? If I understood your case.
The Inspired
I I have started to create a webapp called TweetApp just for learning purpose, where users can tweet and like the tweets. So I want to check whether the tweet is liked by the logged in user. I'm using class based listview for that... I thought to do annotation. Or something else... Still clueles... Anyway to do that?
another way of thinking: instead of doing all that mumbo-jumbo. Simply wrap the function for liking a tweet inside a @login_required, so that a user can only like a tweet if they are logged in. Otherwise when they click on the like button and they are not logged in, then it will redirect them to the login page
Human
Class Posts(models.Model): tweet =charfield() likes = ManytoManyfield(User, on_delete= models. Cascade) updated = datetimefield()
Human
The model is something like this
Human
Using listview I'm showing list of posts in the feed.
Beka
Using listview I'm showing list of posts in the feed.
for example, like this... red heart.. I've liked your message. You want the same functionality in back-end?
Human
Whenever the user sees the posts, he should know that he is liked the post or not.
Beka
from django.http import JsonResponse from .models import Post def like_post(request): if request.method == 'POST' and request.user.is_authenticated: post_id = request.POST.get('post_id') post = Post.objects.get(pk=post_id) post.likes.add(request.user) return JsonResponse({'status': 'liked'}) return JsonResponse({'status': 'error'}) def unlike_post(request): if request.method == 'POST' and request.user.is_authenticated: post_id = request.POST.get('post_id') post = Post.objects.get(pk=post_id) post.likes.remove(request.user) return JsonResponse({'status': 'unliked'}) return JsonResponse({'status': 'error'}) later, in your listview: Your just check post by user like if user like exists. Is it make sense now?
Human
I'm using Class based view
Beka
I'm using Class based view
does not matter... you just check for existence
Human
class FeedView(LoginRequiredMixin, ListView): login_url = "/login/" redirect_field_name = "login" model = Posts template_name = "feed.html" def get_queryset(self): search = self.request.GET.get("q") qs = super().get_queryset().filter(user__in=[i.user for i in UserProfile.objects.get(user=self.request.user).followers.all()]) if search: return qs.filter(user__first_name__icontains=search) return qs
Human
class Posts(models.Model): tweet = models.CharField(max_length=200) slug = models.SlugField(null=True) updated = models.DateTimeField(auto_now=True) created = models.DateTimeField(auto_now_add=True) likes = models.ManyToManyField(User, related_name="liked_posts", null=True, blank=True) user = models.ForeignKey(User, on_delete=models.CASCADE) def save(self, **kwrgs): uname = self.tweet[:20] if Posts.objects.filter(slug=uname).exists(): extra = str(randint(1, 10000)) self.slug = slugify(uname) + "-" + extra else: self.slug = slugify(uname) return super().save() def __str__(self) -> str: return self.tweet def likes_count(self): return self.likes.count()
Human
Sorry make this chat like this . The first one is my view and second one is my model
Beka
Sorry make this chat like this . The first one is my view and second one is my model
What issue you're getting now? Better to paste the issue.
Kriti
Also any source, which can help me learn how to write tests for djnago applications.
Human
What issue you're getting now? Better to paste the issue.
Still I couldn't sort it out ... Like how to show if the post is liked by the logged in user....
Kriti
please share the link
Beka
Still I couldn't sort it out ... Like how to show if the post is liked by the logged in user....
What do you mean by "to show", like in front-end? Please be specific with the issue.
Beka
I've been giving you solutions but you're still facing the issue. Maybe, we just did not understand each other.
Human
Yeah in the front end I want to show that liked or not... Got it?