Best Way to set min/max values in Django Model field












0















I'm trying to get a field called WipID in my model to have the following:
- Primary Key
- and to have numbers between 000000001 and 999999999



Basically I want the field to always have 9 numbers. I don't care about auto-increment or not.



I've tried a number variations, but right now I have this:



WipID = models.BigAutoField(primary_key=True, validators=[MinValueValidator(000000001), MaxValueValidator(999999999)])


I've tried BigIntegerField and PositiveIntegerfield and those haven't worked either.



What's the best way to accomplish this? Any help is greatly appreciated on this.










share|improve this question























  • 000000001 isn't a number, it's a string. The number is just 1.

    – dirkgroten
    Nov 20 '18 at 16:35






  • 1





    What's the point in saving "00000001" to the database? Just use 1 - 999999999 using what you have now (MinValueValidator(1) is correct way of doing it) and if you want to display it differently, write a custom @property on your model to display the field as string with prepending the 0s.

    – dirkgroten
    Nov 20 '18 at 16:37













  • The information that we are using this for requires 9 digits ID's. So if I have something with an ID number of 1 in the database, but I display it as 000000001, nobody is going to know to search for just "1". Is my thinking right on this or no?

    – Dan
    Nov 20 '18 at 16:49
















0















I'm trying to get a field called WipID in my model to have the following:
- Primary Key
- and to have numbers between 000000001 and 999999999



Basically I want the field to always have 9 numbers. I don't care about auto-increment or not.



I've tried a number variations, but right now I have this:



WipID = models.BigAutoField(primary_key=True, validators=[MinValueValidator(000000001), MaxValueValidator(999999999)])


I've tried BigIntegerField and PositiveIntegerfield and those haven't worked either.



What's the best way to accomplish this? Any help is greatly appreciated on this.










share|improve this question























  • 000000001 isn't a number, it's a string. The number is just 1.

    – dirkgroten
    Nov 20 '18 at 16:35






  • 1





    What's the point in saving "00000001" to the database? Just use 1 - 999999999 using what you have now (MinValueValidator(1) is correct way of doing it) and if you want to display it differently, write a custom @property on your model to display the field as string with prepending the 0s.

    – dirkgroten
    Nov 20 '18 at 16:37













  • The information that we are using this for requires 9 digits ID's. So if I have something with an ID number of 1 in the database, but I display it as 000000001, nobody is going to know to search for just "1". Is my thinking right on this or no?

    – Dan
    Nov 20 '18 at 16:49














0












0








0








I'm trying to get a field called WipID in my model to have the following:
- Primary Key
- and to have numbers between 000000001 and 999999999



Basically I want the field to always have 9 numbers. I don't care about auto-increment or not.



I've tried a number variations, but right now I have this:



WipID = models.BigAutoField(primary_key=True, validators=[MinValueValidator(000000001), MaxValueValidator(999999999)])


I've tried BigIntegerField and PositiveIntegerfield and those haven't worked either.



What's the best way to accomplish this? Any help is greatly appreciated on this.










share|improve this question














I'm trying to get a field called WipID in my model to have the following:
- Primary Key
- and to have numbers between 000000001 and 999999999



Basically I want the field to always have 9 numbers. I don't care about auto-increment or not.



I've tried a number variations, but right now I have this:



WipID = models.BigAutoField(primary_key=True, validators=[MinValueValidator(000000001), MaxValueValidator(999999999)])


I've tried BigIntegerField and PositiveIntegerfield and those haven't worked either.



What's the best way to accomplish this? Any help is greatly appreciated on this.







python django django-models






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 15:14









DanDan

616




616













  • 000000001 isn't a number, it's a string. The number is just 1.

    – dirkgroten
    Nov 20 '18 at 16:35






  • 1





    What's the point in saving "00000001" to the database? Just use 1 - 999999999 using what you have now (MinValueValidator(1) is correct way of doing it) and if you want to display it differently, write a custom @property on your model to display the field as string with prepending the 0s.

    – dirkgroten
    Nov 20 '18 at 16:37













  • The information that we are using this for requires 9 digits ID's. So if I have something with an ID number of 1 in the database, but I display it as 000000001, nobody is going to know to search for just "1". Is my thinking right on this or no?

    – Dan
    Nov 20 '18 at 16:49



















  • 000000001 isn't a number, it's a string. The number is just 1.

    – dirkgroten
    Nov 20 '18 at 16:35






  • 1





    What's the point in saving "00000001" to the database? Just use 1 - 999999999 using what you have now (MinValueValidator(1) is correct way of doing it) and if you want to display it differently, write a custom @property on your model to display the field as string with prepending the 0s.

    – dirkgroten
    Nov 20 '18 at 16:37













  • The information that we are using this for requires 9 digits ID's. So if I have something with an ID number of 1 in the database, but I display it as 000000001, nobody is going to know to search for just "1". Is my thinking right on this or no?

    – Dan
    Nov 20 '18 at 16:49

















000000001 isn't a number, it's a string. The number is just 1.

– dirkgroten
Nov 20 '18 at 16:35





000000001 isn't a number, it's a string. The number is just 1.

– dirkgroten
Nov 20 '18 at 16:35




1




1





What's the point in saving "00000001" to the database? Just use 1 - 999999999 using what you have now (MinValueValidator(1) is correct way of doing it) and if you want to display it differently, write a custom @property on your model to display the field as string with prepending the 0s.

– dirkgroten
Nov 20 '18 at 16:37







What's the point in saving "00000001" to the database? Just use 1 - 999999999 using what you have now (MinValueValidator(1) is correct way of doing it) and if you want to display it differently, write a custom @property on your model to display the field as string with prepending the 0s.

– dirkgroten
Nov 20 '18 at 16:37















The information that we are using this for requires 9 digits ID's. So if I have something with an ID number of 1 in the database, but I display it as 000000001, nobody is going to know to search for just "1". Is my thinking right on this or no?

– Dan
Nov 20 '18 at 16:49





The information that we are using this for requires 9 digits ID's. So if I have something with an ID number of 1 in the database, but I display it as 000000001, nobody is going to know to search for just "1". Is my thinking right on this or no?

– Dan
Nov 20 '18 at 16:49












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396053%2fbest-way-to-set-min-max-values-in-django-model-field%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396053%2fbest-way-to-set-min-max-values-in-django-model-field%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)