Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String Reference in Model Container Error #683

Open
rudra-cruv opened this issue Nov 14, 2023 · 0 comments
Open

String Reference in Model Container Error #683

rudra-cruv opened this issue Nov 14, 2023 · 0 comments

Comments

@rudra-cruv
Copy link

Can't Use string reference in model container for defining related models.

Python script

from djongo import models

class CartCustomization(models.Model):
    class Meta:
        abstract = True
    
    id = models.CharField(max_length=300)
    name = models.CharField(max_length=100)
    quantity = models.IntegerField()
    price = models.IntegerField()
    customization_categories = models.ArrayField(model_container = "CartCustomizationCategory")


class CartCustomizationCategory(models.Model):
    class Meta:
        abstract = True

    id = models.CharField(max_length=300)
    name = models.CharField(max_length=100)
    customizations = models.ArrayField(model_container=CartCustomization)

class CartItem(models.Model):
    class Meta:
        abstract = True

    id = models.CharField(max_length=300)
    name = models.CharField(max_length=100)
    parent_item_id = models.CharField(max_length=12)
    quantity = models.IntegerField()
    price = models.IntegerField()
    customization_categories = models.ArrayField(model_container=CartCustomizationCategory)

Traceback

Traceback (most recent call last):
File "D:\CRUV\craver-backend\craver\manage.py", line 22, in
main()
File "D:\CRUV\craver-backend\craver\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "D:\CRUV\craver-backend\venv\Lib\site-packages\django\core\management_init_.py", line 442, in execute_from_command_line
utility.execute()
File "D:\CRUV\craver-backend\venv\Lib\site-packages\django\core\management_init_.py", line 416, in execute
django.setup()
File "D:\CRUV\craver-backend\venv\Lib\site-packages\django_init_.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\CRUV\craver-backend\venv\Lib\site-packages\django\apps\registry.py", line 116, in populate
app_config.import_models()
File "D:\CRUV\craver-backend\venv\Lib\site-packages\django\apps\config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\rudra\AppData\Local\Programs\Python\Python311\Lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "D:\CRUV\craver-backend\craver\cart\models.py", line 6, in
class CartCustomization(models.Model):
File "D:\CRUV\craver-backend\craver\cart\models.py", line 14, in CartCustomization
customization_categories = models.ArrayField(model_container = "CartCustomizationCategory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\CRUV\craver-backend\venv\Lib\site-packages\djongo\models\fields.py", line 276, in init
super().init(model_container, *args, **kwargs)
File "D:\CRUV\craver-backend\venv\Lib\site-packages\djongo\models\fields.py", line 114, in init
self.model_container._meta.abstract = False
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '_meta'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant