Skip to content

Django Defered Model Reference lookup #9

Closed
@pnhowe

Description

@pnhowe

When two models cross reference each other, Django will defer linking one of the ForeignKeys's related model. This causes django_orm to get a string instead of the model when resolving the model field. A ValueError is currently thrown when this happens. Some how we need to find the hook to fully resolve the model.

Example:

@cinp.model()
class Job( models.Model ):
  JOB_TARGET_CHOICES = ( ( 'foundation', 'foundation' ), ( 'structure', 'structure' ) )
  JOB_ACTION_CHOICES = ( ( 'build', 'build' ), ( 'destroy', 'destroy' ), ( 'move', 'move' ) )
  history_entry = models.OneToOneField( 'History', on_delete=models.CASCADE )
  target = models.CharField( max_length=10, choices=JOB_TARGET_CHOICES )
  action = models.CharField( max_length=7, choices=JOB_ACTION_CHOICES )

@cinp.model( )
class History( models.Model ):
  target = models.CharField( max_length=Job._meta.get_field( 'target' ).max_length, choices=Job.JOB_TARGET_CHOICES )
  action = models.CharField( max_length=Job._meta.get_field( 'action' ).max_length, choices=Job.JOB_ACTION_CHOICES )
  started = models.DateTimeField()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions