django-models

How to get the value of a Django Model Field object

半城伤御伤魂 提交于 2020-12-27 08:19:08
问题 I got a model field object using field_object = MyModel._meta.get_field(field_name) . How can I get the value (content) of the field object? 回答1: Use value_from_object: field_name = 'name' obj = MyModel.objects.first() field_object = MyModel._meta.get_field(field_name) field_value = field_object.value_from_object(obj) Which is the same as getattr : field_name = 'name' obj = MyModel.objects.first() field_object = MyModel._meta.get_field(field_name) field_value = getattr(obj, field_object

How to resolve AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' in Django

為{幸葍}努か 提交于 2020-12-27 05:37:24
问题 I have been trying to post data in my Django application using ajax post. The data is getting saved but in the terminal I am coming up against the following error: AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' Here are the relevant codes intended to achieve my goal: Views.py: def saveMaterial(request): if request.is_ajax and request.method == "POST": form = CreateMaterialForm(request.POST) # It's a ModelForm mat_bom_list = CreateBomMatListFormset(request.POST,

How to resolve AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' in Django

余生颓废 提交于 2020-12-27 05:36:48
问题 I have been trying to post data in my Django application using ajax post. The data is getting saved but in the terminal I am coming up against the following error: AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' Here are the relevant codes intended to achieve my goal: Views.py: def saveMaterial(request): if request.is_ajax and request.method == "POST": form = CreateMaterialForm(request.POST) # It's a ModelForm mat_bom_list = CreateBomMatListFormset(request.POST,

How to resolve AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' in Django

北城以北 提交于 2020-12-27 05:36:46
问题 I have been trying to post data in my Django application using ajax post. The data is getting saved but in the terminal I am coming up against the following error: AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' Here are the relevant codes intended to achieve my goal: Views.py: def saveMaterial(request): if request.is_ajax and request.method == "POST": form = CreateMaterialForm(request.POST) # It's a ModelForm mat_bom_list = CreateBomMatListFormset(request.POST,

How to resolve AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' in Django

余生颓废 提交于 2020-12-27 05:36:21
问题 I have been trying to post data in my Django application using ajax post. The data is getting saved but in the terminal I am coming up against the following error: AttributeError: 'ModelFormOptions' object has no attribute 'concrete_model' Here are the relevant codes intended to achieve my goal: Views.py: def saveMaterial(request): if request.is_ajax and request.method == "POST": form = CreateMaterialForm(request.POST) # It's a ModelForm mat_bom_list = CreateBomMatListFormset(request.POST,

how to use Django filtered class data to 2 seperate view

被刻印的时光 ゝ 提交于 2020-12-26 04:26:40
问题 I am using Django filter and using it in normal view it is working as expected now I want to download the filtered data so for this I am writing one download view where I am trying to use the same FilterClass but no luck. It is giving me an ERROR( Exception Value: type object 'CTSFilter' has no attribute 'values_list' ). Can anyone please help/suggest how to use filtered queryset in filter class more than one view OR pass the data of filtered query to the download views. Please find my code.

Reverse for 'blog_detail' with no arguments not found. 1 pattern(s) tried: ['blog/(?P<pk>[0-9]+)$']

匆匆过客 提交于 2020-12-15 07:29:54
问题 Reverse for 'blog_detail' with no arguments not found. Reverse for 'blog_detail' with no arguments not found. 1 pattern(s) tried: ['blog/(?P[0-9]+)$'] models.py class Blog(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) title = models.CharField(max_length=80) slug = models.SlugField(max_length=80, unique=True, db_index=True, blank=True, null=True) description = models.TextField(max_length=1080, blank=True, null=True) image = models.ImageField

Reverse for 'blog_detail' with no arguments not found. 1 pattern(s) tried: ['blog/(?P<pk>[0-9]+)$']

*爱你&永不变心* 提交于 2020-12-15 07:28:08
问题 Reverse for 'blog_detail' with no arguments not found. Reverse for 'blog_detail' with no arguments not found. 1 pattern(s) tried: ['blog/(?P[0-9]+)$'] models.py class Blog(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) title = models.CharField(max_length=80) slug = models.SlugField(max_length=80, unique=True, db_index=True, blank=True, null=True) description = models.TextField(max_length=1080, blank=True, null=True) image = models.ImageField

How to correctly use Django reverse FK lookup to show instances of the child model in CBV

ぃ、小莉子 提交于 2020-12-15 07:02:12
问题 I have two models, field of one of them pointing to the other as shown below: class Group(models.Model): group_company_id = models.CharField(primary_key=True, ...) class Company(models.Model): company_id = models.CharField(primary_key=True, ...) group_company = models.ForeignKey(Group, related_name="related_grp_company", ...) I am trying to get all the Companies that have been created for a particular Group . So I am trying to get the company_id (and other) values in Djnago UpdateView as a

data doesn't appear in my html page when i add new record - Django

旧街凉风 提交于 2020-12-15 06:26:13
问题 when i add new record from admin panel it should appear in html page , but it doesn't do that how to fix it models.py : class BestArticals(models.Model): name = models.CharField(max_length=240) url = models.URLField(default="",max_length=240) image = models.ImageField(upload_to='images/',null=True, blank=True) def get_image(self): if self.image and hasattr(self.image, 'url'): return self.image.url else: return '/path/to/default/image' def __str__(self): return self.name views.py : from