[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Support missing field types #17

Open
jordaneremieff opened this issue Dec 19, 2020 · 2 comments · Fixed by #28
Open

Support missing field types #17

jordaneremieff opened this issue Dec 19, 2020 · 2 comments · Fixed by #28

Comments

@jordaneremieff
Copy link
Owner

Currently the Postgres field types aren't supported (except JSONField). Maybe others.

@ievans3024
Copy link
ievans3024 commented Jun 3, 2021

Can confirm that django.db.models.ImageField is also not working.

The following will raise UnboundLocalError: local variable 'python_type' referenced before assignment at the declaration of BSchema:

import os.path
from uuid import uuid4

from django.db import models
from djantic import ModelSchema


def upload_image_handler(instance, filename):
    _, ext = os.path.splitext(filename)
    _uuid = uuid4()
    return f'{_uuid}{ext}'


class NameMixin(models.Model):
    name = models.CharField(max_length=128)

    class Meta:
        abstract = True


class ImageMixin(models.Model):
    image = models.ImageField(blank=True, null=True, upload_to=upload_image_handler)

    class Meta:
        abstract = True


class A(NameMixin):
    a = models.IntegerField()
   
    
class B(ImageMixin, NameMixin):
    b = models.IntegerField()
    
    
class ASchema(ModelSchema):
    class Config:
        model = A


class BSchema(ModelSchema):
    class Config:
        model = B

@jordaneremieff
Copy link
Owner Author

@ievans3024 thanks for the report. I've merged some minimal support for file fields here.

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

Successfully merging a pull request may close this issue.

2 participants