mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Create a custom URL field, which allows the user-specified validators
- Ref: https://stackoverflow.com/questions/41756572/django-urlfield-with-custom-scheme - Apply this to the URL field in the Part model
This commit is contained in:
parent
ee17d5d3c3
commit
4ac8353099
27
InvenTree/InvenTree/fields.py
Normal file
27
InvenTree/InvenTree/fields.py
Normal file
@ -0,0 +1,27 @@
|
||||
""" Custom fields used in InvenTree """
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .validators import allowable_url_schemes
|
||||
|
||||
from django.forms.fields import URLField as FormURLField
|
||||
from django.db import models as models
|
||||
from django.core import validators
|
||||
|
||||
|
||||
class InvenTreeURLFormField(FormURLField):
|
||||
""" Custom URL form field with custom scheme validators """
|
||||
|
||||
default_validators = [validators.URLValidator(schemes=allowable_url_schemes())]
|
||||
|
||||
|
||||
class InvenTreeURLField(models.URLField):
|
||||
""" Custom URL field which has custom scheme validators """
|
||||
|
||||
default_validators = [validators.URLValidator(schemes=allowable_url_schemes())]
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
return super().formfield(**{
|
||||
'form_class': InvenTreeURLFormField
|
||||
})
|
19
InvenTree/part/migrations/0023_auto_20190913_1401.py
Normal file
19
InvenTree/part/migrations/0023_auto_20190913_1401.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.5 on 2019-09-13 14:01
|
||||
|
||||
import InvenTree.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0022_auto_20190908_0918'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='part',
|
||||
name='URL',
|
||||
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to extenal URL'),
|
||||
),
|
||||
]
|
@ -34,6 +34,7 @@ import hashlib
|
||||
from InvenTree import helpers
|
||||
from InvenTree import validators
|
||||
from InvenTree.models import InvenTreeTree
|
||||
from InvenTree.fields import InvenTreeURLField
|
||||
|
||||
from InvenTree.status_codes import BuildStatus, StockStatus, OrderStatus
|
||||
|
||||
@ -353,7 +354,7 @@ class Part(models.Model):
|
||||
|
||||
revision = models.CharField(max_length=100, blank=True, help_text='Part revision or version number')
|
||||
|
||||
URL = models.URLField(blank=True, help_text='Link to extenal URL')
|
||||
URL = InvenTreeURLField(blank=True, help_text='Link to extenal URL')
|
||||
|
||||
image = models.ImageField(upload_to=rename_part_image, max_length=255, null=True, blank=True)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user