Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:28:14+00:00 2026-06-18T02:28:14+00:00

The problem is that I am working on a Django Admin project, which should

  • 0

The problem is that I am working on a Django Admin project, which should be able to accept CIDR format data and put that into database (Postgres).

Let’s say I have a model:

##################################################
class CIDR(models.Model):
    ....
    net_cidr = models.IPAddressField(unique=True)
    ....

    def __unicode__(self):
        return self.net_cidr

##################################################

Based on the above code, the net_cidr field in the database is of inet type, which supports the CIDR format data. However, IPAddressField doesn’t support CIDR (at least doesn’t work for me). If I want to enter something on my admin site like “128.66.0.0/16”, Django will pop an error, telling me to “Enter a valid IPv4 address”.

I have tried to change the field type to Char, and it works (of course). However, it is not a good idea to set CIDR as varchar in the database.

Basically what I want is to let net_cidr to be able to accpet an IP Range, like “128.66.0.0-128.66.255.255” or a CIDR block “128.66.0.0/16” and save it to database as
“128.66.0.0/16”.

I think the key part is how to let IPAddressField accept a string type (like an IP range or CIDR block) data. Then I can convert it to CIDR block and save it to database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:28:15+00:00Added an answer on June 18, 2026 at 2:28 am

    There are many ways to achieve what you need.

    What I would do is to define net_cidr as a models.CharField.

    Then define a modelform for your model where you are going to implement
    the clean_net_cidr function.

    class CIDRForm(ModelForm):
        def clean_net_cidr(self):
            # do your magic processing here
    
        class Meta:
            model = CIDR
    

    and then pass that form to the model admin object

    class CIDRAdmin(admin.ModelAdmin):
        form = CIDRForm
    

    UPDATE:

    It seems this is exactly what you need, based on your comments.
    https://github.com/jimfunk/django-postgresql-netfields

    Among other fields, it includes a CidrAddressField

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a problem that occurred to me while working on a Django project.
I'm working on a Django 1.2.3 project, and I'm finding that the admin session
I am working on a mathematical problem that has the advantage of being able
I am working on a django project that requires much of the common page
I am working on a Django web based project in which i need to
I've been working on a django project for a while now that uses grappelli
I'm working on a Django project, and I've created some custom admin views using
I'm working on Django website that should give a possibility to select cooking recipes
I have a problem that I'm working on for quite some time now. I
I have a problem that I had working in a test but now in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.