Simple edc-search forms and view mixins for the 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
edc-search-0.3.6.tar.gz
(26.8 kB
view hashes)
Built Distribution
edc_search-0.3.6-py3-none-any.whl
(25.0 kB
view hashes)
Close
Hashes for edc_search-0.3.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18f15cf369bfd53387a026db5d2112b97706a510142cd385d4ed3f3e7da43516 |
|
MD5 | fd47f1bbb0693fefb478fcb42aebb477 |
|
BLAKE2b-256 | e5c2b1ceca943e3b6a5423cd2a28be5e50467cf38d89f1ab8cfe42052b6ad53b |