Slug Field Is Accepting Whitespace When Entered Through Django Shell.
The web framework for perfectionists with deadlines.
- Overview
- Download
- Documentation
- News
- Community
- Code
- Issues
- About
- ♥ Donate
- Login
- Preferences
- View Tickets
- Reports
- Timeline
- Wiki
- Search
Context Navigation
- ← Previous Ticket
- Next Ticket →
Opened 5 years ago
Closed 5 years ago
#32207 closed Bug (invalid)
Slug field is accepting whitespace when entered through Django shell.| Reported by: | Harshvardhan Anand | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.1 |
| Severity: | Normal | Keywords: | slug; prepopulated; error reporting; sqlite |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I am using Django 3.1.3 with Python 3.7.6.
- Slug field is accepting whitespaces when updated from Django shell.
- Slug field is not prepopulated if data(like title) is entered from Django shell.
But if slug is entered with whitespaces from admin panel then it will raise error. And similarly if we create data(e.g. - title) from admin panel slug field is prepopulated.
I have also created a video(saved in google drive) explaining the issue.
In the image below, you can see the slug field with whitespaces -
The model I have defined in models.py is
class Post(models.Model): STATUS_CHOICES = ( ('draft', 'Draft'), ('published', 'Published') ) title = models.CharField(max_length=250) slug = models.SlugField(max_length=250, unique_for_date='publish') author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_post') body = models.TextField() publish = models.DateTimeField(default=timezone.now) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft') class Meta: ordering = ('-publish',) def __str__(self): return self.titleModified admin panel -
@admin.register(Post) class PostAdmin(admin.ModelAdmin): list_display = ('title', 'slug', 'author', 'publish', 'status') list_filter = ('status', 'created', 'publish', 'author') search_fields = ('title', 'body') prepopulated_fields = {'slug':('title',)} raw_id_fields = ('author',) date_hierarchy = 'publish' ordering = ('status', 'publish')Attachments (1)
db.png (31.8 KB ) - added by Harshvardhan Anand 5 years ago.Download all attachments as: .zip
Oldest first Newest first Show comments Show property changesChange History (2)
by Harshvardhan Anand, 5 years ago
| Attachment: | db.png added |
|---|
comment:1 by Claude Paroz, 5 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
This is expected behavior. The SlugField functionality is implemented though validation, which is activated by the forms infrastructure or by manually calling full_clean() on some model. If you set a value and save, you are on your own, there are no database-level checks. You can see the exact same behaviour for other fields like URLField.
Note: See TracTickets for help on using tickets.Download in other formats:
- RSS Feed
- Comma-delimited Text
- Tab-delimited Text
Learn More
- About Django
- Getting Started with Django
- Team Organization
- Django Software Foundation
- Code of Conduct
- Diversity Statement
Get Involved
- Join a Group
- Contribute to Django
- Submit a Bug
- Report a Security Issue
- Individual membership
Get Help
- Getting Help FAQ
- Django Discord
- Official Django Forum
Follow Us
- GitHub
- Fediverse (Mastodon)
- News RSS
Support Us
- Sponsor Django
- Corporate membership
- Official merchandise store
- Benevity Workplace Giving Program
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django Software Foundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.
Từ khóa » đan Slug
-
What Is A "slug" In Django? - Stack Overflow
-
Django Slug Tutorial
-
Add The Slug Field Inside Django Model - GeeksforGeeks
-
Django-slug-preview - PyPI
-
43 - Slugs In Dynamic Urls - Python & Django 3.2 Tutorial Series
-
Using Translated Slugs In Views — Django-parler 2.3 Documentation
-
URL Dispatcher - Django Documentation
-
Marcanuy/django-slugs-example-app: A Basic App To Show ... - GitHub
-
Changing Page Settings — Django Cms 3.4.7 Documentation
-
Slug In Django | Delft Stack
-
12. How To Use Slug Field With Django For More Readability?
-
Installation — Django-primary-slug V0.1.1b1 Documentation
-
Dan Slug | Facebook