Simple edc-search forms and view mixins for clinicedc/edc
Project description
edc-search
Add a slug field to models using the model mixin SearchSlugModelMixin. Specify the fields and/or properties to include in the slug in search_slug_fields:
class TestModel(SearchSlugModelMixin, models.Model):
search_slug_fields = ['f1', 'f2', 'f3']
f1 = models.CharField(max_length=25, null=True)
f2 = models.DateTimeField(null=True)
f3 = models.IntegerField(null=True)
f4 = models.CharField(max_length=25, null=True)
Fields in the search_slug_fields are converted to string in the slug:
>>> obj = TestModel.objects.create(f1='run rabbit run!', f2=get_utcnow(), f3=12345)
>>> obj.slug
'run-rabbit-run!|2017-06-02 19:08:32.163520+00:00|12345'
Fields not listed are not included:
>>> obj = TestModel.objects.create(f1='slug me', f4='don\'t slug me')
>>> obj.slug
'slug-me||'
Null fields are converted to '':
>>> obj = TestModel.objects.create()
>>> obj.slug
'||'
You can use dotted syntax:
class TestModel(SearchSlugModelMixin, models.Model):
search_slug_fields = ['f1', 'name.first', 'name.last']
f1 = models.CharField(max_length=25, null=True)
def name(self):
return FullName(first='Gore', last='vidal')
>>> obj = TestModel.objects.create()
>>> obj.slug
'|Gore|Vidal'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for edc-search-0.1.6.macosx-10.13-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a77169590ba40a8bbc7cdc01e5daa992b3a984693e47ecbc4fe449879ca8036e |
|
MD5 | 92ffba04eea38210712039e420573ea8 |
|
BLAKE2b-256 | d4b1965fc0c9e401ed22d3d59ab6c3f70d48deca46d4a9a85f3c94bbc9aac088 |
Close
Hashes for edc_search-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65f320708165a5be84990c7571623bbdfd913ae6d8d1121e67571c9da048885e |
|
MD5 | 5ebb9918116184bfaf3a2862f9561bb0 |
|
BLAKE2b-256 | 818b80cf906dfe8edba2d46495411e28194598f7388c72b3f120638a1107975b |