kmmbvnr / django-any Goto Github PK
View Code? Open in Web Editor NEW[DEPRICATED] Unobtrusive test models creation for django
License: MIT License
[DEPRICATED] Unobtrusive test models creation for django
License: MIT License
django_any don't know native django.db.models.fields.files.ImageField field type...
Currently I have to write following code to generate model:
any_model(Comment,
content_type=ContentType.objects.get_for_model(Question),
object_id=question.id,
content_object=question)
but I believe it should be:
any_model(Comment, content_object=question)
It looks that it can be achieved if you pass instance kwarg to decorator. What do you think about this?
user = any_model(User, active=True)
I spent a lot of time until understand the error. If any_model raise the error "is not the correct parameter" (must be is_active) - I would saved a lot of time.
Thank you!
field_choices_attibute is written in following way that model_choice_field_data will be never called using any_form(FormClass), because ModelChoiceField.choices by default is:
[('', '----------------')]
So field_choices_attibute will return ''. It is valid, but I don't see any reason to do so.
Plus it looks like model_choice_field_data should return pk, not the object itself. Should I send pull request?
django_any don't work with django-modeltranslation which is sad. Below is traceback with details:
Traceback (most recent call last):
File "/home/max/testproject/tweets/tests.py", line 77, in test_widget
content = any_model(Content, slug='test', title='Test')
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/functions.py", line 90, in __call__
return self._create_value(*args, **kwargs)
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/functions.py", line 87, in _create_value
return function(*args, **kwargs)
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/models.py", line 441, in any_model_default
_fill_model_fields(result, **kwargs)
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/models.py", line 431, in _fill_model_fields
setattr(model, field.name, any_field(field, **fields_args[field.name]))
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/functions.py", line 90, in __call__
return self._create_value(*args, **kwargs)
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/models.py", line 53, in wrapper
return function(field, **kwargs)
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/models.py", line 36, in wrapper
return function(field, **kwargs)
File "/home/max/.testprojectenv/lib/python2.6/site-packages/django_any/functions.py", line 85, in _create_value
raise TypeError("no match %s" % field_type)
TypeError: no match <class 'modeltranslation.fields.TranslationField'>
Hi @kmmbvnr,
For a while I was a maintainer of the friendly fork of this package - django-whatever.
Recently, its author delegated me rights for releasing new version on PyPi (I made some updates already).
Are you interested in delegating maintenance? I think it makes more sense releasing new versions with the original name.
Extra comma:
double-underscore
syntax as django orm,Having used django-any in a couple of projects i strongly prefer to fill fields with sane values from model classes instead of weird stuff.
Don't know where to put this so here's just some code instead of fork/PR:
def lazy_model(cls, **attrs):
"""Use model-provided defaults"""
from django.db.models.fields import NOT_PROVIDED
from inspect import isfunction, ismethod
for field in cls._meta.fields:
default = field.default
if default is not NOT_PROVIDED:
if isfunction(default) or ismethod(default):
# for stuff like default=datetime.now
default = default()
attrs.setdefault(field.name, default)
return any_model(cls, **attrs)
django-any can not properly populate models with recursion. For example such models causes infinity recursion:
class Question(models.Model):
accepted_answer = models.ForeignKey('Answer')
class Answer(models.Model):
question = models.ForeignKey(Question)
module 'unittest' from '/usr/lib/python2.7/unittest/__init__.py'
There, i fixed it! (in django_any/test.py)
try:
from unittest import _strclass
except ImportError:
_strclass = str
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.