Skip to content

Django Defered Model Reference lookup #9

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

Closed
pnhowe opened this issue Dec 12, 2017 · 1 comment
Closed

Django Defered Model Reference lookup #9

pnhowe opened this issue Dec 12, 2017 · 1 comment

Comments

@pnhowe
Copy link
Member

pnhowe commented Dec 12, 2017

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()
@pnhowe
Copy link
Member Author

pnhowe commented Aug 8, 2019

resolved in recent version

@pnhowe pnhowe closed this as completed Aug 8, 2019
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