django-models

how can i add an expiration date function on a model?

爷,独闯天下 提交于 2021-02-08 10:40:28
问题 i am trying to make a key verification app that when accepted it would create the same app on the user's profile, so i have done everything but i have struggled making the expiration date part, i want the expired boolean become true when the date is expired, but i have no idea on how to implement it #models.py class ProductKey(models.Model): product = models.ForeignKey(Product, on_delete=models.CASCADE, unique=False) key = models.CharField(max_length=14) valid_from = models.DateTimeField

How to handle to GET request in in same FBV(function based View.)

我与影子孤独终老i 提交于 2021-02-08 10:40:19
问题 Hello Everyone I am a beginner in Django and I have created one webpage where the user is able to search/Filter results and for this, I have used the Django-filter concept. Now my requirement is user should be able to download that filtered data. To achieve this I have created one separate View class with a download name and trying to pass the same Filter Class Queryset but with no luck, it is giving me all model data (records). Please find the Post: how to use Django filtered class data to 2

custom User model with auto_now_add=True causes “non-editable field” Exception in UserAdmin

懵懂的女人 提交于 2021-02-08 10:01:11
问题 I'm learning python Django. I have created a custom user model and it is working, but whenever I visit any user's profile through the Django admin I get this error: Exception Value: 'date_joined' cannot be specified for UserProfile model form as it is a non-editable field. Check fields/fieldsets/exclude attributes of class UserAdminModel. This is my custom UserProfile model: class UserProfile(AbstractBaseUser, PermissionsMixin): """ A model for authors and readers.""" first_name = models

custom User model with auto_now_add=True causes “non-editable field” Exception in UserAdmin

馋奶兔 提交于 2021-02-08 10:00:52
问题 I'm learning python Django. I have created a custom user model and it is working, but whenever I visit any user's profile through the Django admin I get this error: Exception Value: 'date_joined' cannot be specified for UserProfile model form as it is a non-editable field. Check fields/fieldsets/exclude attributes of class UserAdminModel. This is my custom UserProfile model: class UserProfile(AbstractBaseUser, PermissionsMixin): """ A model for authors and readers.""" first_name = models

Steps to add model level permission in Django

时光总嘲笑我的痴心妄想 提交于 2021-02-08 08:24:39
问题 I have my legacy database.I created models using inspectdb.I am able to see my tables in admin page . I created 4 users and i want to implement role-based permission for each model. I just show you with example what i did in model to add permissions like edit, view, delete. Example:- class BusinessIntegrationSourceCategory(models.Model): date_added = models.DateTimeField(blank=True, null=True) date_modified = models.DateTimeField(blank=True, null=True) source_category = models.CharField(max

JSON Encoding with Django adding extra \\ characters

半世苍凉 提交于 2021-02-08 05:11:34
问题 I'm trying to create a function that will convert a dictionary containing a message and a Django model instance into JSON, that I can pass back to the client. For example, I have the model Test defined in models.py. from django.db import models class Test(models.Model): test_field = models.CharField(max_length=40) I've defined this extension of the simplejson JSONEncoder based on the this stackoverflow question: from django.core.serializers import serialize from django.utils.simplejson import

Django Admin: add inlines dynamically

ぐ巨炮叔叔 提交于 2021-02-08 05:08:32
问题 class MyTemplateAdmin(admin.ModelAdmin): list_display = ('name') search_fields = ['name'] inlines = [ Template1Inline, Template2Inline, Template3Inline, ] This works fine. But what I need is to make it dynamic. Whenever the admin adds a new Template to the MyTemplate Model, that needs to be added to the inlines. Is there a way to do this? Please comment if I am not clear enough on my question. Thanks in advance! 回答1: I haven't tested this, but in theory you could do: class MyTemplateAdmin

how to hide or show fields of model after clicked on choice field from admin in django

回眸只為那壹抹淺笑 提交于 2021-02-08 03:34:50
问题 class BannerAddPage(models.Model): BOOL_CHOICES = ((True, 'Live'), (False, 'Pause')) TYPE_CHOICES = (('text', 'text'), ('image', 'image')) category=models.ForeignKey(Category,blank=True) client=models.ForeignKey(Client) ad_type=models.CharField(choices=TYPE_CHOICES,default=True) ad_name=models.CharField(max_length=800,null=True,blank=True) ad_title=models.CharField(max_length=800,null=True,blank=True) ad_url1=models.URLField(max_length=800,blank=True,null=True) ad_banner2=models.ImageField

how to hide or show fields of model after clicked on choice field from admin in django

不打扰是莪最后的温柔 提交于 2021-02-08 03:34:05
问题 class BannerAddPage(models.Model): BOOL_CHOICES = ((True, 'Live'), (False, 'Pause')) TYPE_CHOICES = (('text', 'text'), ('image', 'image')) category=models.ForeignKey(Category,blank=True) client=models.ForeignKey(Client) ad_type=models.CharField(choices=TYPE_CHOICES,default=True) ad_name=models.CharField(max_length=800,null=True,blank=True) ad_title=models.CharField(max_length=800,null=True,blank=True) ad_url1=models.URLField(max_length=800,blank=True,null=True) ad_banner2=models.ImageField

How to use multiple user models in Django?

核能气质少年 提交于 2021-02-08 01:51:57
问题 I'm trying to use two user models with different 'username' type each one. First user type is an administrator who login in with username and password. Second, a customer who login with phone number and password. Only the customer has custom fields. I tried customize the Django User model but it only allows one auth user model. I am thinking use an authentication backend. Administrator only will login in admin dashboard, while customer only login in application. Edit. Different problem from.