mλdcodez
# in models.py
class Entry(models.Model):
...
tags = models.ManyToManyField(Tag)
class Tag(models.Model):
slug = models.SlugField(max_length=200, unique=True)
def __str__(self):
return self.slug
# in template [home.html]
# {% for object in object_list %}
{% for tag in object.tags.all %}
{{object.tags.all}} <!-- returns this : [<Tag: world>] [<Tag: country>] [<Tag: city>] -->
{% endfor %}
{% endfor %} #
i wish to compare the tag with a string say, 'city', how can i. I'm trying for like an hour. stackoverflow, django docs etc. can't find solution, I'm new to django, Please Help.
mλdcodez
Leo
I guess what you want to compare to is the tag.slug-attribute
Leo
Because you don’t want to compare the String „city“ to the tag object, but check wether the tag’s slug is „city“ or not.
mλdcodez
yep.
mλdcodez
btw, this works:
{% if object.tags.all|join:"" == "city" %}}
<small>CITY</small>
{% endif %}
Anonymous
Hi guys,
I'm trying to use auth django login to handle my users login
I do like this
Anonymous
views.py —> left
urls.py —> right
Anonymous
and i use my login.html page in website/templates/registration/
but when i try to login nothing happend
I was go to admin page and login then I come to / url
and it's ok
but when i try to login with my templates nothing happend at all
Anonymous
Iman
I don't know what you mean
Next concept is for redirecting the user to that path after successful login.
If you want to redirect all users to a specific path use the LOGIN_REDIRECT_URL
Django Bot
>> Jobs
- Python Engineer
inchidi
not sure but maybe something like this will work
class Category(models.Model):
...
class Meta:
verbose_name = _('category')
verbose_name_plural = _('categories')
mλdcodez
okay :)
mλdcodez
Thanks. but, i already defined these
class Meta:
verbose_name = "Blog Entry"
verbose_name_plural = "Blog Entries"
ordering = ["-created"]
mλdcodez
using 1.8
Mahesh
Guys can anyone suggest me some good python project topic
Mahesh
For college project
Mahesh
For minor project
mλdcodez
Something like this: http://arkansasfamilydental.com
Leo
mλdcodez
Leo
Btw, it is recommended to give classes singular names!
mλdcodez
One more thing.
mλdcodez
class BlogIndex(generic.ListView):
queryset = models.Entry.objects.published()
template_name = "home.html"
paginate_by = 4
i wish to the category class, how can i, instead of models.Entry.objects.published()
mλdcodez
this seems idiotic to ask. sorry, I'll figure it out. :)
Django Bot
>> Links
- django-rest-witchcraft 0.6.2 : Python Package Index
Leo
I'm new to django, I'll keep that in mind, thanks 😊😊😊😊
And it has a reason: Think of the model as a template for an Object. You don’t want to store multiple Objects that are “Categories” each, but multiple objects that are a Category each. But you can just refactor from “Categories” to “Category”, Django will recognize the change when running “makemigrations” and rename your Database tables for you
inchidi
mλdcodez
Trying
Mahesh
What's the python version rqd for django
?
mλdcodez
2.7 or 3.x
Meitar
I think minimum of 3.4
Meitar
But I know that they stopped support 2.7
Meitar
https://docs.djangoproject.com/en/2.0/faq/install/
Mahesh
But 2.7 is pre-installed in Ubuntu
mλdcodez
Install 3.x
mλdcodez
Hope you know how to install
mλdcodez
Mahesh
Hmm
Mahesh
I hve python3 also
Mahesh
It's 3.5.1
mλdcodez
Then enjoy
Django Bot
>> Links
- Creating websites using React and Django REST Framework
Anonymous
Hello, is there anyone able to convert an html page to a WordPress theme? He/she will be paid
Django Bot
>> Links
- Building Data Products with Python: A Wine Review Website using Django and
Anonymous
Pls help me any for windows django setup
Django Bot
>> Links
- Linux'izing your Windows PC into a dev machine
- Django development with Docker —A completed development cycle
Django Bot
>> Blogs
- Container Runtimes Part 2: Anatomy of a Low-Level Container Runtime
- Synchronizing Django model definitions
>> Links
- Learn Python Programming Online with the Real Python Team – Real Python
- Let's talk about usernames
Omer
A good tutorial about django rest framework?
Omer
Thanks, I'll check it out
Anonymous
Django Bot
>> Blogs
- Basics of Django Rest Framework
>> Links
- The Book
- pydanny/cookiecutter-django: Cookiecutter Django is a framework for jumpsta
- What I Wish I Knew When I Started Django Development 2018 - Thoughts. Stuff
Anonymous
hi, how can i run python script like xml validation from admin.py in django?
Leo
Huh?
Leo
You want to validate your input data, right?
Ismael
Hi guys, anyone knows how to parse a querydict to a "normal" dict, just as come from the method?
Javi
Anonymous
yes validate xml file with xsd
Leo
Then refer to validation in the docs ;)
Anonymous
Anonymous
It is almost same.
Anonymous
Well query dict is there to deal with multiple values for same key.
Ismael
p{1:2,3:4} turns to {'p[1]':2, 'p[3]':4}
Anonymous
Ismael
Wot
querydict.dict() returns that
Anonymous
Weird
Ismael
just django 2.x
Anonymous
Well that shouldn't happen.
Anonymous
Can share log?
Anonymous
*you
Ismael
yes, tomorrow, im not at work 😁
Anonymous
thanks, work perfectly