Questions tagged [django-custom-field]

django-custom-field refers to an ability to create custom model fields in Django

refers to an ability to create custom model fields in Django.

See documentation.

31 questions
1
vote
0 answers

django custom model fields

Im trying to create my own custom model field following this guide https://docs.djangoproject.com/en/2.1/howto/custom-model-fields/ class Hand: """A hand of cards (bridge style)""" def __init__(self, north, east, south, west): #…
Leap
  • 158
  • 11
1
vote
1 answer

How to create key value data type in django 1.7 models

I want to store key-value pair in one column. Above >Django-1.7 provides hstore to do that. But I want to same functionality in Django-1.7. How can I create custom datatype to store key-value pair in one column. I am using postgres-9.5 database. I…
1
vote
2 answers

Django Custom Decimal Field - best way to have automatic float to double conversion?

I have few places in database when I'm using DecimalField. Unfortunalety I have to handle both double and float data as input - and there is my problem. I want to do brutal cut off the value (after second decimal place), not a math round. I store…
Izzy
  • 755
  • 2
  • 9
  • 17
1
vote
1 answer

Custom Django field does not return Enum instances from query

I have a simple custom field implemented to utilize Python 3 Enum instances. Assigning enum instances to my model attribute, and saving to the database works correctly. However, fetching model instances using a QuerySet results in the enum attribute…
lgunsch
  • 71
  • 5
0
votes
0 answers

django primary key auto assigning available id from least value

In django project primary key are assigned automatically. In my model I have some model object with id (=5,6). id (= 1,2,3,4,) is deleted from the DB. Now when I create new object model,django assigning id with the value 7. But I want this to assign…
0
votes
1 answer

How i can handle django nested serializer with django sub nested model

I want to find a more conventional way to handle the Django nested serializer with Django sub-nested models. I have created these two models with override function get_attribute. It's works fine for me but I'm, looking for a more conventional way to…
0
votes
2 answers

Django Custom User Model Failes to encrypt password from admin site

I have created a custom user model by inheriting AbstractBaseUser, PermissionsMixin and also created a Custom Manager for creating users and superuser. But when I try to add new user from Django admin site, it fails to encrypt the password field and…
0
votes
1 answer

How to create simple custom field in django?

I want to create two additional properties of TextField such as property1 and property2 so that I can access them in template like {% for field in form %} {{ field.property1 }} {{ field.property2 }} {% endfor %} my current model looks…
Pritam
  • 333
  • 3
  • 13
0
votes
1 answer

django delete s3 image uploaded using custom field

I am using a custom field to upload image on s3 using django 1.9. I want to delete image from s3 whenever model instance is deleted. I have tried post_delete signal with ImageField's delete() method but since I'm using custom field cannot achieve…
0
votes
1 answer

Django Custom Model Field - formfield not working

I've been scratching my head for a while now over this one. I'm trying to build a custom model field to store postal address. The general idea is to store all data after serializing in a models.TextField, and to use a form.MultiValueField to catch…
TonyEight
  • 316
  • 3
  • 11
0
votes
1 answer

How to change the value of custom model field displayed in django admin

I have this code: import re import six from django.core.validators import validate_email from django.db.models import TextField, SubfieldBase class EmailsListField(TextField): __metaclass__ = SubfieldBase email_separator_re =…
Aaron Schif
  • 2,421
  • 3
  • 17
  • 29
0
votes
0 answers

Django Exception Value: 'TextInput' object has no attribute 'clean'

I met the following problem with Django 1.6. I try to create a custom MultiValueField and catch an error during submitting the form. Error appears in "django/forms/fields.py in clean, line 993": clean_data.append(field.clean(field_value)) Local…
sche
  • 1
  • 2
0
votes
1 answer

Django custom field gives an error when editing in admin

I'm trying to implement a custom Django field that would keep in DB a name of one of my model classes (e. g. "Cat", "Dog", "Restaurant", "SuperPrivateCommercialDataPiece", etc.) and return the class object when requested: class Cat(models.Model): …
Tigran Saluev
  • 3,351
  • 2
  • 26
  • 40
0
votes
2 answers

django - How to make exception for oracle backend in custom field?

THE PROBLEM: I'm writing custom django model field. In get_db_prep_save(self, value, connection) I need to do exception for oracle backend and behave differently from other backends. So I'm looking for the best, official and most elegant way of…
mnowotka
  • 16,430
  • 18
  • 88
  • 134
0
votes
1 answer

TypeError when trying to JSON serialise a custom Django model field

I have written a custom Django Model Field to store dateutil.relativedelta's. The field looks like this: class RelativeDeltaField(models.CharField): description = "Relative delta" __metaclass__ = models.SubfieldBase max_length = 200 …
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248