Djangosnippets
91 FOLLOWERS
Djangosnippets.org is a site for users of the Django web framework to come together and share useful "snippets" of reusable code. Browse through snippets organized by author, language, or by tag. You can also have a look at the top-rated snippets and the most-bookmarked snippets.
Djangosnippets
3M ago
If you have multiple items in a list and want them to be displayed as human readable list of items, this will add the proper punctuation to generate the text. You'll need to provide a conjugation to the end of the list like "or" or "and"; it defaults to "or ..read more
Djangosnippets
3M ago
add JSONRequestMiddleware to your enabled middleware in Django settings. Now, in your view functions, you can call request.json() to get a parsed json body! json is consumed lazily, and cached ..read more
Djangosnippets
11M ago
Creates a model serializer class on the fly, just taking the model (class) as its argument.
My use case: When importing data from spreadsheets, the DRF serializers are an easy way to create model instances from a dictionary. This function saves me from creating a custom serializer each time I ..read more
Djangosnippets
1y ago
Don't forget to replace "self.image" by your image field name from your model ex ( self.cover ) replace Product by your model name
works pretty well ..read more
Djangosnippets
1y ago
Sometimes a plain-text help-text isn't sufficient, and it's handy to be able to add links to pages, documentation or external websites.
This javascript snippet can be added to your page, in combination with adding a class to your help text in your template. This assumes you're using jQuery on your ..read more
Djangosnippets
1y ago
A simple jQuery javascript that collapses all stacked inline rows for better handling of large inline fieldsets.
It also adds "Show"/"Hide"-buttons for showing/hiding each row, which could be customized and styled using css.
Usage (see below for example):
Include the javascript on your admin page, together with jQuery, and it'll ..read more
Djangosnippets
1y ago
Add fields and extend Django's built-in Group model using a OneToOneField (i.e. a profile model). In this example, we add a UUIDField. Whenever a new group is created, we automatically (via signals) create a corresponding Role record referencing the newly created group. Whenever a Group is deleted, the corresponding ..read more
Djangosnippets
1y ago
A more simple version of https://djangosnippets.org/snippets/1688/, inheriting from SelectDateWidget, overriding only the necessarily.
Usage example:
In models.py:
from django.db import models
from django.utils.translation import gettext_lazy as _
class MyModel(models.Model):
start = models.DateField(
_("Start date"),
)
end = models.DateField(
_("End date"),
)
class Meta:
verbose_name = _("My model")
In ..read more
Djangosnippets
1y ago
Hey Friends,
In this quick example, let's see django tutorial & crud example with mysql and bootstrap. step by step explain django crud operations with mysql backend. step by step explain django crud operations with mysql bootstrap. let’s discuss about django crud operations with mysql database.
Read more...
https://tuts-station.com/python-django-crud-example-tutorial.html ..read more