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

add reproductibility to issue 77 #81

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions example/issue_77/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,36 @@ class ObjC(models.Model):
relA = models.ForeignKey(ObjA, on_delete=models.CASCADE, related_name="objcs")
relB = models.ForeignKey(ObjB, on_delete=models.CASCADE, related_name="objcs")
value = models.FloatField()

def populate():
print("POPULATE DATABASE FOR ISSUE 77")

try:
a1 = ObjA.objects.create(id=1, name="A_1")
except:
pass

try:
b1 = ObjB.objects.create(id=1, name="B_1")
except:
pass
try:
b2 = ObjB.objects.create(id=2, name="B_2")
except:
pass

try:
c1 = ObjC.objects.create(id=1, relA=a1, relB=b1, value=0)
except:
pass
try:
c2 = ObjC.objects.create(id=2, relA=a1, relB=b2, value=0)
except:
pass

print(ObjA.objects.all())
print(ObjB.objects.all())
print(ObjC.objects.all())


#populate()
6 changes: 6 additions & 0 deletions example/unicorn/components/issue_77.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def __init__(self, *args, **kwargs):
self.obja = ObjA.objects.get(pk=kwargs["pk"])

def set_left(self, pk):
print("OBJ L")
print(pk)
self.objc_left = ObjC.objects.get(pk=pk)
print(self.objc_left)

def set_right(self, pk):
print("OBJ R")
print(pk)
self.objc_right = ObjC.objects.get(pk=pk)
print(self.objc_right)
20 changes: 5 additions & 15 deletions example/unicorn/templates/unicorn/issue-77.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
<div>
<select name="left">
{% for x in obja.objcs.all %}
<option value="{{ x.id }}" unicorn:click="set_left({{ x.id }})">{{ x }}</option>
<option value="{{ x.id }}" unicorn:click="set_left({{ x.id }})">{{ x.relB.name }}</option>
{% endfor %}
</select>

<select name="right">
{% for x in objb.objcs.all %}
<option value="{{ x.id }}" unicorn:click="set_right({{ x.id }})">{{ x }}</option>
{% for x in obja.objcs.all %}
<option value="{{ x.id }}" unicorn:click="set_right({{ x.id }})">{{ x.relB.name }}</option>
{% endfor %}
</select>

<hr />

<select name="left" unicorn:model="objc_left">
{% for x in obja.objcs.all %}
<option value="{{ x.id }}">{{ x }}</option>
{% endfor %}
</select>

<select name="right" unicorn:model="objc_right">
{% for x in objb.objcs.all %}
<option value="{{ x.id }}">{{ x }}</option>
{% endfor %}
</select>
<p>LEFT : {{ objc_left.relB.name }}</p>
<p>RIGHT : {{ objc_right.relB.name }}</p>
</div>