Git Product home page Git Product logo

django-any's People

Contributors

kmmbvnr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

django-any's Issues

ContentType and GenericForeignKey

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?

field_choices_attibute hides model_choice_field_data

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?

Don't work with django-modeltranslation

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'>

Are you interested in delegating django-any maintenance?

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.

quickstart.txt - type errors

Extra comma:

  • "django-any allows to specify only fields important for test,
    and fill rest by random with acceptable values."
  • "django-any will preserve all field constrants <wrong spelling - constraints>, such as max_length, and choices when filling models with random data."
  • "django-any supports the same double-underscore syntax as django orm,
    for setting subfields values"
  • "You could use Q objects, for selection values for fields from fixtures"
  • "If you test sometimes fails, in error log, you could found used random seed"
  • "You could use this seed, to repeat and debug you <wrong spelling - your> tests, with exactly the same random data"

Use defaults from model where available

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)

Models with recursion

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.