add artificial key for shopping_event_groceries
This commit is contained in:
@@ -10,8 +10,9 @@ Base = declarative_base()
|
|||||||
shopping_event_groceries = Table(
|
shopping_event_groceries = Table(
|
||||||
'shopping_event_groceries',
|
'shopping_event_groceries',
|
||||||
Base.metadata,
|
Base.metadata,
|
||||||
Column('shopping_event_id', Integer, ForeignKey('shopping_events.id'), primary_key=True),
|
Column('id', Integer, primary_key=True, autoincrement=True), # Artificial primary key
|
||||||
Column('grocery_id', Integer, ForeignKey('groceries.id'), primary_key=True),
|
Column('shopping_event_id', Integer, ForeignKey('shopping_events.id'), nullable=False),
|
||||||
|
Column('grocery_id', Integer, ForeignKey('groceries.id'), nullable=False),
|
||||||
Column('amount', Float, nullable=False), # Amount of this grocery bought in this event
|
Column('amount', Float, nullable=False), # Amount of this grocery bought in this event
|
||||||
Column('price', Float, nullable=False) # Price of this grocery at the time of this shopping event
|
Column('price', Float, nullable=False) # Price of this grocery at the time of this shopping event
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -158,7 +158,10 @@ const ShoppingEventForm: React.FC = () => {
|
|||||||
|
|
||||||
const getGroceryName = (id: number) => {
|
const getGroceryName = (id: number) => {
|
||||||
const grocery = groceries.find(g => g.id === id);
|
const grocery = groceries.find(g => g.id === id);
|
||||||
return grocery ? grocery.name : 'Unknown';
|
if (!grocery) return 'Unknown';
|
||||||
|
|
||||||
|
const weightInfo = grocery.weight ? `${grocery.weight}${grocery.weight_unit}` : grocery.weight_unit;
|
||||||
|
return `${grocery.name} ${weightInfo}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loadingEvent) {
|
if (loadingEvent) {
|
||||||
@@ -250,7 +253,7 @@ const ShoppingEventForm: React.FC = () => {
|
|||||||
<option value={0}>Select a grocery</option>
|
<option value={0}>Select a grocery</option>
|
||||||
{groceries.map(grocery => (
|
{groceries.map(grocery => (
|
||||||
<option key={grocery.id} value={grocery.id}>
|
<option key={grocery.id} value={grocery.id}>
|
||||||
{grocery.name} ({grocery.category})
|
{grocery.name} ({grocery.category}) {grocery.weight ? `${grocery.weight}${grocery.weight_unit}` : grocery.weight_unit}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user