Giter Site home page Giter Site logo

krisfields / django-baker Goto Github PK

View Code? Open in Web Editor NEW
388.0 388.0 51.0 29 KB

Adds a management command that generates views, forms, urls, admin, and templates based off the contents of models.py

License: BSD 3-Clause "New" or "Revised" License

Python 76.03% HTML 23.97%

django-baker's People

Contributors

alkelaun avatar jlec avatar krisfields avatar metatrevor avatar timonweb 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-baker's Issues

TemplateDoesNotExist error

HI,

I'm getting TemplateDoesNotExist error (running locale on MacOs).

Template loader postmortem report that it looked into django.template.loaders.app_directories.Loader: /anaconda3/lib/python3.6/site-packages/django_baker/templates/base.html

while pip install put templates into /anaconda3/lib/python3.6/site-packages/django_baker/templates/django_baker/

python 3 support?

  File "/srv/bbb/lib/python3.4/site-packages/django_baker/management/commands/bake.py", line 54
    print app_label, model_names
                  ^
SyntaxError: Missing parentheses in call to 'print'

Python 2 only?

init should use absolute imports to be compatible with Python 3+

From Python 3+, absolute imports are the default. This breaks the behavior of the views init.py since it uses relative imports.

It just needs to change the way it generates the init.py file from:

from myview_views import * #NOQA

to:

from .myview_view import * #NOQA

I'll try to write a pull request for this later.

issue when adding django_baker in INSTALLED_APPS

Greeting,
After a successful installation of djano_baker with the command:

pip install django_baker
i added the following in setting as mentioned in the readme page as mentioned bellow :
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_baker' ]
when running python3 manage.py runserver i get this error
Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run autoreload.raise_last_exception() File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception raise _exception[1] File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 398, in execute autoreload.check_errors(django.setup)() File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/apps/registry.py", line 124, in populate app_config.ready() File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/contrib/admin/apps.py", line 27, in ready self.module.autodiscover() File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/contrib/admin/__init__.py", line 50, in autodiscover autodiscover_modules("admin", register_to=site) File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 58, in autodiscover_modules import_module("%s.%s" % (app_config.name, module_to_search)) File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/home/anis/fjango/my_venv/lib/python3.10/site-packages/django_baker/admin.py", line 2, in <module> from django.db.models.fields import FieldDoesNotExist ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' (/home/anis/fjango/my_venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py)
if possible can tI get some help to resolve tis probleme
more information:
python version : Python 3.10.6
django version: 4.1.5
Ubuntu version: 22.04

ImproperlyConfigured at /create/

Specifying both 'fields' and 'form_class' is not permitted.

After running bake and going to the create view, I get the error mentioned in the title. This is a fresh bake with no modifications to the generated views.py.

However maybe it's left up to the user to decide which to use?

I'm using django 1.8.7

Errors unless logged in

You get errors unless you're logged in. Without an auth app, that likely means from the admin. I think it's worth mentioning in the README.

Shouldn't try to automatically generate non-editable fields

I'm using this with a model that has a MoneyField from https://github.com/django-money/django-money/

It creates a field that has multiple options, and some are set to be non-editable. For instance, I can set the currency in the model, but the user can't choose the currency.

When using baker, it raises an exception when trying to create a currency field. For example:

FieldError at /vehicles/
'purchase_price_currency' cannot be specified for CompanyOwnedVehicle model form as it is a non-editable field

It should check to see if a field is non-editable before trying to generate it.

Not compatible with Py3k?

I've tried running this on a Python 3 project and I got the following error:

  File "-deleted-/lib/python3.4/site-packages/django_baker/management/commands/bake.py", line 54
    print app_label, model_names
                  ^
SyntaxError: Missing parentheses in call to 'print'

Seems like there is not reason to support Python 2 and Python 3, is this project still in active development? If so I can work on a pull request if desired.

Django 3.0 support

I had this error:

File "/home/username/.local/lib/python3.7/site-packages/django_baker/bakery.py", line 10, in <module>
    from django.utils.six import iteritems
ModuleNotFoundError: No module named 'django.utils.six'

i changed it into
from six import iteritems
and now it works.

sintax error using django 1.8 and python2.7.

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/core/management/init.py", line 312, in execute
django.setup()
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/contrib/admin/init.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/marc/geonode-dev/.venvs/djangocaketut/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/marc/djangocaketut/djangocaketut/bread/admin.py", line 2
from .models import
^
SyntaxError: invalid syntax

Exception Value: 'EmailValidator' object has no attribute 'regex'

both with py2 and py3 I get this when accessing the baked admin view

Exception Type: AttributeError
Exception Value:

'EmailValidator' object has no attribute 'regex'

Exception Location: /usr/local/lib/python2.7/site-packages/django_baker/admin.py in is_urlfield, line 45

Django 2.0?

Hello,

Does this project support Django 2.0 running on Python 3.6?

I get the following error using bake.

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django_baker/management/commands/bake.py", line 23, in handle
    baker.bake(ingredients)
  File "/usr/local/lib/python3.6/site-packages/django_baker/bakery.py", line 28, in bake
    self.create_init_files(app, model_names.keys(), models)
  File "/usr/local/lib/python3.6/site-packages/django_baker/bakery.py", line 70, in create_init_files
    "model_names_dict": model_names_dict
  File "/usr/local/lib/python3.6/site-packages/django_baker/bakery.py", line 120, in create_file_from_template
    new_file.write(get_template(template_path).render(Context(context_variables)))
  File "/usr/local/lib/python3.6/site-packages/django/template/backends/django.py", line 59, in render
    context = make_context(context, request, autoescape=self.backend.engine.autoescape)
  File "/usr/local/lib/python3.6/site-packages/django/template/context.py", line 274, in make_context
    raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)
TypeError: context must be a dict rather than Context.

The automatically created forms don't understand how to handle file uploads.

Forms should use enctype="multipart/form-data" if files are in the model.

Alternatively, forms could always use enctype="multipart/form-data" and developers could comment it out if they needed increased efficiency.

Example of form with working file uploads:
<form enctype="multipart/form-data" method="post" action="/foo/">

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.