I need help

62 views
Skip to first unread message

Fadi Haddad

unread,
Aug 13, 2019, 10:23:41 PM8/13/19
to Django developers (Contributions to Django itself)
Hi, 

I have created a table called dataset

I put the age as integer e.g. 34, 23, 10, 47 

I need to create Age range for the age column. I need the age to be displayed as [1-10], [11,20], [21-30] ... etc. Can this happen by replacing values or do I have to create another column for this? The goal is to anonymize my dataset therefore if it is possible to replace values (age) rather than creating new column would be excellent.   

Can anyone help me how to code this in SQL? Would be appreciated if code is included in the response 

Regards

Fadi

Adam Johnson

unread,
Aug 14, 2019, 3:36:21 AM8/14/19
to django-d...@googlegroups.com
Hi!

I think you've found the wrong mailing list for this post. This mailing list is for the development of Django itself, not for support using Django. This means the discussions of bugs and features in Django itself, rather than in your code using it. People on this list are unlikely to answer your support query with their limited time and energy. Read more on the mailing lists at https://www.djangoproject.com/community/

For support, please use the django-users mailing list, or IRC #django on Freenode, or a site like Stack Overflow. There are people out there willing to help on those channels, but they might not respond if you don't ask your question well. Stack Overflow's question guide can help you frame it well: https://stackoverflow.com/help/how-to-ask .

Also if you haven't read it, please take a look at Django's Code of Conduct: https://www.djangoproject.com/conduct/ . These are our "ground rules" for working well as a community, and will help you get the most out of Django and our fantastic community.

On your question - I think you want the SQL CASE and WHEN which are mapped in the Django ORM as the Case and When functions: https://docs.djangoproject.com/en/2.2/ref/models/conditional-expressions/

Thanks for your understanding,

Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/79b8a25a-ce6b-4a73-9be2-d67c7d78e2ff%40googlegroups.com.


--
Adam

Pavlos Georgiadis

unread,
Aug 14, 2019, 7:08:39 AM8/14/19
to 'Fadi Haddad' via Django developers (Contributions to Django itself)
Hi Fadi,

This is the developers mailing list dedicated to development of django itself. Questions like this should be addressed to the users mailing list.


P.S: Do a search for "django model property decorator" (there is also a cached_property decorator). It will help you find a solution.

--
Pavlos Georgiadis

Become a Physicist

unread,
Aug 14, 2019, 7:08:43 AM8/14/19
to Django developers (Contributions to Django itself)
You can create a drop down menu for this.

AGE_CHOICES = (
('11-20','11-20'),
('21-30', '21-30'),
)

class MyModel(models.Model):
color = models.CharField(max_length=6, choices=AGE_CHOICES, blank=True, null=True)

Hope this helps... 😊
With regards,
Shubham Gupta
Reply all
Reply to author
Forward
0 new messages