Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e03710e
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
*.pyc | |||
.DS_Store | |||
._* | |||
.~*# | |||
*.swp | |||
*.swo | |||
*.swn | |||
.svn | |||
*.orig | |||
_build | |||
build | |||
dist | |||
*.egg-info | |||
docs/_build | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
django-stringfield | |||
================== | |||
|
|||
Copyright (c) 2011, Aino | |||
All rights reserved. | |||
|
|||
Redistribution and use in source and binary forms, with or without | |||
modification, are permitted provided that the following conditions are met: | |||
|
|||
* Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
|
|||
* Redistributions in binary form must reproduce the above copyright | |||
notice, this list of conditions and the following disclaimer in the | |||
documentation and/or other materials provided with the distribution. | |||
|
|||
* Neither the name of the sorl-thumbnail the names of its contributors | |||
may be used to endorse or promote products derived from this software | |||
without specific prior written permission. | |||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
include LICENSE README.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
|
|||
django-stringfield | |||
================== | |||
|
|||
A string field that tries not to enforce length on database level. Currently | |||
implemented as: | |||
|
|||
PostgreSQL | |||
``character varying`` | |||
|
|||
MySQL | |||
``VARCHAR (65528)`` | |||
MySQL >= 5.0.3 should be able to handle a maximum length of 65535 but that | |||
does not work in my empirical testing using mysql 5.1.41 where 65528 is the | |||
maximum considering ``NULL`` and ``NOT NULL``. | |||
|
|||
SQLite & Other backends | |||
``TEXT`` | |||
|
|||
|
|||
Installation | |||
------------ | |||
:: | |||
|
|||
pip install django-stringfield | |||
|
|||
|
|||
Usage | |||
----- | |||
You use this just like the normal ``django.db.models.CharField`` except that the | |||
key word argument ``max_length`` works a little differently: | |||
|
|||
* It is optional and defaults to 255 | |||
* It only enforces max length on the default formfield **not** on the database. | |||
|
|||
Example usage:: | |||
# models.py | |||
from stringfield import StringField | |||
|
|||
class MyModel(models.Model): | |||
name = StringField() | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
from setuptools import setup, find_packages | |||
|
|||
|
|||
setup( | |||
name='django-stringfield', | |||
version='0.1', | |||
description='Better string field for Django.', | |||
long_description=open('README.rst').read(), | |||
author='Mikko Hellsing', | |||
author_email='mikko@aino.se', | |||
license='BSD', | |||
url='https://github.com/aino/django-stringfield', | |||
packages=find_packages(), | |||
zip_safe=False, | |||
classifiers=[ | |||
'Development Status :: 3 - Alpha', | |||
'Environment :: Web Environment', | |||
'Intended Audience :: Developers', | |||
'License :: OSI Approved :: BSD License', | |||
'Operating System :: OS Independent', | |||
'Programming Language :: Python', | |||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content', | |||
'Framework :: Django', | |||
], | |||
) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
from stringfield.base import StringField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
from django.db import models | |||
from django.utils.translation import ugettext_lazy as _ | |||
|
|||
|
|||
class StringField(models.CharField): | |||
description = _("String") | |||
|
|||
def __init__(self, *args, **kwargs): | |||
kwargs['max_length'] = kwargs.get('max_length', 255) | |||
super(models.CharField, self).__init__(*args, **kwargs) | |||
|
|||
def get_internal_type(self): | |||
return "TextField" | |||
|
|||
def to_python(self, value): | |||
if isinstance(value, basestring) or value is None: | |||
return value | |||
return smart_unicode(value) | |||
|
|||
def get_prep_value(self, value): | |||
return self.to_python(value) | |||
|
|||
def formfield(self, **kwargs): | |||
defaults = {'max_length': self.max_length} | |||
defaults.update(kwargs) | |||
return super(CharField, self).formfield(**defaults) | |||
|
|||
def db_type(self, connection): | |||
if connection.vendor == 'postgresql': | |||
return 'character varying' | |||
if connection.vendor == 'mysql': | |||
return 'VARCHAR (65528)' | |||
return 'TEXT' | |||
|
|||
def south_field_triple(self): | |||
from south.modelsinspector import introspector | |||
name = '%s.%s' % (self.__class__.__module__ , self.__class__.__name__) | |||
args, kwargs = introspector(self) | |||
return name, args, kwargs | |||
|